diff --git a/packages/injectable-extension-for-dependency-graphing/README.md b/packages/injectable-extension-for-dependency-graphing/README.md new file mode 100644 index 00000000..71fe4b8a --- /dev/null +++ b/packages/injectable-extension-for-dependency-graphing/README.md @@ -0,0 +1,7 @@ +# Dependency graphing for Injectable in Ogre Tools + +Todo + +## Documentation + +Check unit tests for documentation. diff --git a/packages/injectable-extension-for-dependency-graphing/babel.config.js b/packages/injectable-extension-for-dependency-graphing/babel.config.js new file mode 100644 index 00000000..c383045c --- /dev/null +++ b/packages/injectable-extension-for-dependency-graphing/babel.config.js @@ -0,0 +1,14 @@ +module.exports = { + presets: [ + [ + '@babel/preset-env', + { + targets: { + node: 'current', + }, + }, + ], + + '@babel/react', + ], +}; diff --git a/packages/injectable-extension-for-dependency-graphing/index.d.ts b/packages/injectable-extension-for-dependency-graphing/index.d.ts new file mode 100644 index 00000000..db58680e --- /dev/null +++ b/packages/injectable-extension-for-dependency-graphing/index.d.ts @@ -0,0 +1,19 @@ +import { DiContainer, InjectionToken } from '@ogre-tools/injectable'; + +declare module '@ogre-tools/injectable-extensions-for-dependency-graphing' { + interface GraphCustomizer { + shouldCustomize: (instance: any) => boolean; + // Todo: add proper typing + customizeLink: (link: any) => void; + customizeNode: (node: any) => void; + } + + export const dependencyGraphCustomizerToken: InjectionToken< + GraphCustomizer, + void + >; + + export function registerDependencyGraphing(di: DiContainer): void; + + export const plantUmlDependencyGraphInjectable: InjectionToken; +} diff --git a/packages/injectable-extension-for-dependency-graphing/index.js b/packages/injectable-extension-for-dependency-graphing/index.js new file mode 100644 index 00000000..7037364d --- /dev/null +++ b/packages/injectable-extension-for-dependency-graphing/index.js @@ -0,0 +1,11 @@ +import { + dependencyGraphCustomizerToken, + plantUmlDependencyGraphInjectable, + registerDependencyGraphing, +} from './src/dependency-graphing'; + +export { + registerDependencyGraphing, + plantUmlDependencyGraphInjectable, + dependencyGraphCustomizerToken, +}; diff --git a/packages/injectable-extension-for-dependency-graphing/package-lock.json b/packages/injectable-extension-for-dependency-graphing/package-lock.json new file mode 100644 index 00000000..993e3e95 --- /dev/null +++ b/packages/injectable-extension-for-dependency-graphing/package-lock.json @@ -0,0 +1,13 @@ +{ + "name": "@ogre-tools/injectable-react", + "version": "5.2.0", + "lockfileVersion": 1, + "requires": true, + "dependencies": { + "lodash": { + "version": "4.17.21", + "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz", + "integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==" + } + } +} diff --git a/packages/injectable-extension-for-dependency-graphing/package.json b/packages/injectable-extension-for-dependency-graphing/package.json new file mode 100644 index 00000000..13bcf115 --- /dev/null +++ b/packages/injectable-extension-for-dependency-graphing/package.json @@ -0,0 +1,30 @@ +{ + "name": "@ogre-tools/injectable-extensions-for-dependency-graphing", + "private": false, + "version": "5.2.0", + "description": "Dependency graphing for Injectable in Ogre Tools", + "repository": { + "type": "git", + "url": "https://github.com/ogre-works/ogre-tools" + }, + "main": "build/index.js", + "types": "./index.d.ts", + "keywords": [ + "js" + ], + "author": "Ogre Works", + "license": "MIT", + "dependencies": { + "@ogre-tools/fp": "^5.2.0", + "@ogre-tools/injectable": "^5.2.0", + "lodash": "^4.17.21" + }, + "peerDependencies": {}, + "bugs": { + "url": "https://github.com/ogre-works/ogre-tools/issues" + }, + "homepage": "https://github.com/ogre-works/ogre-tools#readme", + "publishConfig": { + "access": "public" + } +} diff --git a/packages/injectable/src/dependency-injection-container/__snapshots__/createContainer.dependency-graphing.test.js.snap b/packages/injectable-extension-for-dependency-graphing/src/__snapshots__/dependency-graphing.test.js.snap similarity index 100% rename from packages/injectable/src/dependency-injection-container/__snapshots__/createContainer.dependency-graphing.test.js.snap rename to packages/injectable-extension-for-dependency-graphing/src/__snapshots__/dependency-graphing.test.js.snap diff --git a/packages/injectable/src/dependency-injection-container/extensions/dependency-graphing/dependency-graphing.js b/packages/injectable-extension-for-dependency-graphing/src/dependency-graphing.js similarity index 92% rename from packages/injectable/src/dependency-injection-container/extensions/dependency-graphing/dependency-graphing.js rename to packages/injectable-extension-for-dependency-graphing/src/dependency-graphing.js index f6fffe4e..3a624ce1 100644 --- a/packages/injectable/src/dependency-injection-container/extensions/dependency-graphing/dependency-graphing.js +++ b/packages/injectable-extension-for-dependency-graphing/src/dependency-graphing.js @@ -1,17 +1,21 @@ -import getInjectable from '../../../getInjectable/getInjectable'; -import { injectionDecoratorToken } from '../../createContainer'; -import lifecycleEnum from '../../lifecycleEnum'; import camelCase from 'lodash/fp/camelCase'; -import getInjectionToken, { - injectionTokenSymbol, -} from '../../../getInjectionToken/getInjectionToken'; import last from 'lodash/fp/last'; import get from 'lodash/fp/get'; import some from 'lodash/fp/some'; -import { isPromise, pipeline } from '@ogre-tools/fp'; import filter from 'lodash/fp/filter'; import tap from 'lodash/fp/tap'; +import { + getInjectable, + getInjectionToken, + injectionDecoratorToken, + injectionTokenSymbol, + lifecycleEnum, +} from '@ogre-tools/injectable'; + +import { isPromise, pipeline } from '@ogre-tools/fp'; +import lifecycleEnumForDependencyGraphing from './lifecycleEnumForDependencyGraphing'; + export const registerDependencyGraphing = di => { di.register(plantUmlDependencyGraphInjectable); di.register(dependencyGraphStateInjectable); @@ -78,10 +82,10 @@ const plantUmlExtractorInjectable = getInjectable({ if (alias.aliasType === injectionTokenSymbol) { node.isInjectionToken = true; - node.lifecycle = tokenLifecycle; + node.lifecycle = lifecycleEnumForDependencyGraphing.injectionToken; node.infos.add('Token'); } else { - node.lifecycle = alias.lifecycle; + node.lifecycle = lifecycleEnumForDependencyGraphing[alias.lifecycle.id]; } const instanceIsAsync = isPromise(instance); @@ -190,9 +194,3 @@ const toPlantUmlLink = ({ return `${parentId} --${lineStyle}up* ${dependencyId} #text:${textColor} ${infosString} `; }; - -const tokenLifecycle = { - name: 'Transient', - shortName: 'X', - color: 'orange', -}; diff --git a/packages/injectable/src/dependency-injection-container/createContainer.dependency-graphing.test.js b/packages/injectable-extension-for-dependency-graphing/src/dependency-graphing.test.js similarity index 91% rename from packages/injectable/src/dependency-injection-container/createContainer.dependency-graphing.test.js rename to packages/injectable-extension-for-dependency-graphing/src/dependency-graphing.test.js index 239dc669..e451111b 100644 --- a/packages/injectable/src/dependency-injection-container/createContainer.dependency-graphing.test.js +++ b/packages/injectable-extension-for-dependency-graphing/src/dependency-graphing.test.js @@ -1,15 +1,24 @@ -import getDi from '../test-utils/getDiForUnitTesting'; -import getInjectable from '../getInjectable/getInjectable'; - import { dependencyGraphCustomizerToken, plantUmlDependencyGraphInjectable, registerDependencyGraphing, -} from './extensions/dependency-graphing/dependency-graphing'; +} from './dependency-graphing'; import isEqual from 'lodash/fp/isEqual'; -import getInjectionToken from '../getInjectionToken/getInjectionToken'; -import lifecycleEnum from './lifecycleEnum'; +import { + createContainer, + getInjectable, + getInjectionToken, + lifecycleEnum, +} from '@ogre-tools/injectable'; + +const getDi = (...injectables) => { + const di = createContainer(); + + injectables.forEach(di.register); + + return di; +}; describe('createContainer.dependency-graph', () => { it('given dependency graphing, dependencies and injected, creates Plant-UML graph', async () => { diff --git a/packages/injectable-extension-for-dependency-graphing/src/lifecycleEnumForDependencyGraphing.js b/packages/injectable-extension-for-dependency-graphing/src/lifecycleEnumForDependencyGraphing.js new file mode 100644 index 00000000..c3a34a59 --- /dev/null +++ b/packages/injectable-extension-for-dependency-graphing/src/lifecycleEnumForDependencyGraphing.js @@ -0,0 +1,25 @@ +export default { + singleton: { + name: 'Singleton', + shortName: 'S', + color: 'lightGreen', + }, + + keyedSingleton: { + name: 'Keyed', + shortName: 'K', + color: 'pink', + }, + + transient: { + name: 'Transient', + shortName: 'T', + color: 'orchid', + }, + + injectionToken: { + name: 'Transient', + shortName: 'X', + color: 'orange', + }, +}; diff --git a/packages/injectable/index.js b/packages/injectable/index.js index d1235fdf..00a84a31 100644 --- a/packages/injectable/index.js +++ b/packages/injectable/index.js @@ -1,20 +1,19 @@ -import getInjectionToken from './src/getInjectionToken/getInjectionToken'; +import getInjectionToken, { + injectionTokenSymbol, +} from './src/getInjectionToken/getInjectionToken'; + import getInjectable from './src/getInjectable/getInjectable'; import lifecycleEnum from './src/dependency-injection-container/lifecycleEnum'; -import createContainer from './src/dependency-injection-container/createContainer'; -import { - registerDependencyGraphing, - plantUmlDependencyGraphInjectable, - dependencyGraphCustomizerToken, -} from './src/dependency-injection-container/extensions/dependency-graphing/dependency-graphing'; +import createContainer, { + injectionDecoratorToken, +} from './src/dependency-injection-container/createContainer'; export { - getInjectionToken, + createContainer, getInjectable, + getInjectionToken, + injectionDecoratorToken, + injectionTokenSymbol, lifecycleEnum, - createContainer, - registerDependencyGraphing, - plantUmlDependencyGraphInjectable, - dependencyGraphCustomizerToken, }; diff --git a/packages/injectable/ogre-tools-injectable.d.ts b/packages/injectable/ogre-tools-injectable.d.ts index 0728aafa..a9b4b6ea 100644 --- a/packages/injectable/ogre-tools-injectable.d.ts +++ b/packages/injectable/ogre-tools-injectable.d.ts @@ -176,17 +176,4 @@ declare module '@ogre-tools/injectable' { export function createContainer( ...getRequireContexts: (() => RequireContext)[] ): DiContainer; - - interface Customizer { - shouldCustomize: (instance: any) => boolean; - // Todo: add proper typing - customizeLink: (link: any) => void; - customizeNode: (node: any) => void; - } - - export const dependencyGraphCustomizerToken: InjectionToken; - - export function registerDependencyGraphing(di: DiContainer): void; - - export const plantUmlDependencyGraphInjectable: InjectionToken; } diff --git a/packages/injectable/src/dependency-injection-container/lifecycleEnum.js b/packages/injectable/src/dependency-injection-container/lifecycleEnum.js index b318dd95..4f02d57b 100644 --- a/packages/injectable/src/dependency-injection-container/lifecycleEnum.js +++ b/packages/injectable/src/dependency-injection-container/lifecycleEnum.js @@ -3,23 +3,17 @@ export const storedInstanceKey = Symbol('stored-instance-key'); export default { singleton: { - name: 'Singleton', - shortName: 'S', - color: 'lightGreen', + id: 'singleton', getInstanceKey: () => storedInstanceKey, }, keyedSingleton: ({ getInstanceKey }) => ({ - name: 'Keyed', - shortName: 'K', - color: 'pink', + id: 'keyedSingleton', getInstanceKey, }), transient: { - name: 'Transient', - shortName: 'T', - color: 'orchid', + id: 'transient', getInstanceKey: () => nonStoredInstanceKey, }, };