{"_id":"@brainhubeu/sqrs-inversify","_rev":"18-b0d5652744d34fcc1620811d1c6c9859","name":"@brainhubeu/sqrs-inversify","dist-tags":{"latest":"1.0.3"},"versions":{"1.0.3":{"name":"@brainhubeu/sqrs-inversify","version":"1.0.3","author":{"url":"https://github.com/rkostrzewski","name":"Rafał Kostrzewski"},"license":"MIT","_id":"@brainhubeu/sqrs-inversify@1.0.3","maintainers":[{"name":"rkostrzewski","email":"poczta.raf.kos@gmail.com"},{"name":"kkoscielniak","email":"krystiankoscielniak@gmail.com"},{"name":"brainhubeu-ci","email":"dev@brainhub.pl"},{"name":"szymon.morawski","email":"szymon.morawski@brainhub.pl"},{"name":"szulcd2","email":"szulcd2@gmail.com"},{"name":"piotr-s-brainhub","email":"piotr.sroczkowski@brainhub.pl"},{"name":"dyoda","email":"lukasz.pluszczewski@gmail.com"},{"name":"drymek","email":"marcin@dryka.pl"},{"name":"brainhub-adam","email":"adam@brainhub.pl"}],"homepage":"https://github.com/brainhubeu/sqrs#readme","bugs":{"url":"https://github.com/brainhubeu/sqrs/issues"},"dist":{"shasum":"a3e7db0b2f146020514b32d1c71f7c5d5cae99a7","tarball":"https://registry.npmjs.org/@brainhubeu/sqrs-inversify/-/sqrs-inversify-1.0.3.tgz","fileCount":8,"integrity":"sha512-5d1lmgkPk5QZaB8R6YgUhnCcT+n1O+SVmtFXkgX+JnOe8uGBgNGjwEiSPUicPI3BYRWnVuPMMZcDQG7Amo9uuw==","signatures":[{"sig":"MEUCIQC/4GpcG+0XMoTY5UD6F+PgqZAGANPZndOVTHbhJ/JNNQIgb+iML0zbFNsHcOy9MVhqlM23RORL/gmLuIQposaaDzM=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":10192,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJeeH1XCRA9TVsSAnZWagAAQnwP/jA/mbxBJyqJtuJF6XuE\nJDpFVA/VW0aNhFC0d5LZeiiADkFP4llvYWQFyIg0JA3gDeUEH6vw+7e7SFXy\nBG7WJ/qPAhSO+Flt6IgCHALhzJxkxGAU7b4wWKZcQb5f6PHdqXQrF5KwbgOb\nS/s/86qFPiYWIPnBQe3Wl2Z/nz4IOHRBNowXvajTDR4Lvi2LTHxUINXqJ0ih\nWDgZRbeL6bmPEExusS2KlyewyYDxRLR3GPgwjxAIR0Aci1c8Rm6bGy0lArI8\ndmh/PlQjScYIwmUQM2tVey0aivD42xnPMWhxiQShi/bAWCRdLmLhgk7+dmjs\nxqXIHWzORtY4Cb54VhhfgDq/tlV6doJap98G2mZSBqm03vesuu1uCG8uZpQP\nhPkXenFBANWOaf1NCpAaTrPAas2AoarlIyh3WMqRh/Q9niLit80xCGE587SA\nO91CkEkv9btW0AeEuHZzMclhvo1mDqZYb54BiRtrpFT2dBumGBc+UPBeTMAv\nUhygezl7VX+NsZymDieAKJFEH4B0f9b31hpywfawM76Ulm92JocPr85NTwDf\n1hmYLa6rC1hB69TX8ZQieDfGBfc4Co/gS6Z5VlNJJGyDehQtizyTyYLN8VeM\nrfzywcyzjX585t/8MOswiYkyI4lSNm9a2CtO08l15S3Lr7U+qlQi2x2HT+Bc\nYyco\r\n=4XT3\r\n-----END PGP SIGNATURE-----\r\n"},"jest":{"preset":"ts-jest","setupFiles":["<rootDir>/testSetup.ts"]},"main":"dist/index.js","types":"dist/index.d.ts","gitHead":"703186670f7b5fd0fb7549e6566c1709119e1084","scripts":{"lint":"tslint --project ./tsconfig.json 'src/**/*'","test":"jest","build":"tsc --outDir dist","prebuild":"rimraf dist"},"_npmUser":{"name":"rkostrzewski","email":"poczta.raf.kos@gmail.com"},"repository":{"url":"git+ssh://git@github.com/brainhubeu/sqrs.git","type":"git"},"_npmVersion":"lerna/3.20.2/node@v10.16.0+x64 (darwin)","description":"InversifyJS helpers for sqrs package","directories":{},"_nodeVersion":"10.16.0","dependencies":{"inversify-vanillajs-helpers":"2.0.0"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"jest":"^25.1.0","rimraf":"^2.6.2","tslint":"^5.11.0","ts-jest":"^25.2.1","inversify":"^5.0.1","typescript":"^3.8.3","@types/jest":"^23.3.13","@brainhubeu/sqrs":"^1.0.3","reflect-metadata":"^0.1.12"},"peerDependencies":{"inversify":"^5.0.0","@brainhubeu/sqrs":"^1.0.0"},"_npmOperationalInternal":{"tmp":"tmp/sqrs-inversify_1.0.3_1584954711405_0.41547489942356575","host":"s3://npm-registry-packages"}}},"time":{"created":"2020-03-23T09:11:51.159Z","modified":"2024-10-25T13:04:50.213Z","1.0.3":"2020-03-23T09:11:51.515Z"},"bugs":{"url":"https://github.com/brainhubeu/sqrs/issues"},"author":{"url":"https://github.com/rkostrzewski","name":"Rafał Kostrzewski"},"license":"MIT","homepage":"https://github.com/brainhubeu/sqrs#readme","repository":{"url":"git+ssh://git@github.com/brainhubeu/sqrs.git","type":"git"},"description":"InversifyJS helpers for sqrs package","maintainers":[{"email":"angjeziorska@gmail.com","name":"angjez"},{"email":"mateusz.jarzebowski.bownik@gmail.com","name":"matt-jb"},{"email":"filip.kublin@brainhub.pl","name":"fkublin"},{"email":"cypherq@gmail.com","name":"benedyktdryl"},{"email":"dariusz.luber@gmail.com","name":"dluber"},{"email":"devops@brainhub.pl","name":"brainhubeu-devops"},{"email":"anna.lach@brainhub.pl","name":"annalach"},{"email":"szymon.morawski@brainhub.pl","name":"szymon.morawski"},{"email":"lukasz.pluszczewski@gmail.com","name":"dyoda"},{"email":"dev@brainhub.pl","name":"brainhubeu-ci"},{"email":"robert_hebel@icloud.com","name":"roberthebel"}],"readme":"# sqrs-inversify\n\nThis package provides helpers for using [sqrs](/packages/sqrs) with [InversifyJS](https://github.com/inversify/InversifyJS/) library.\n\n## Usage\n\n### SQRS Module\n\nSQRS module registers all handler providers and default implementation of the buses.\n\n```ts\nimport { Container } from 'inversify';\nimport { commandBusId, CommandBus } from '@brainhubeu/sqrs';\nimport { SQRSModule } from '@brainhubeu/sqrs-inversify';\n\nconst container = new Container();\n\ncontainer.load(SQRSModule);\n\n// Will resolve to DefaultCommandBus\nconst commandBus = container.get<CommandBus>(commandBusId);\n```\n\n### ContainerBuilder\n\n`ContainerBuilder` is a helper class that allows you to use InversifyJS without decorators in type safe manner.\n\nExample usage of `ContainerBuilder`:\n```ts\nimport {\n  CommandHandler,\n  eventBusId,\n  EventBus,\n  Dependencies,\n} from '@brainhubeu/sqrs';\nimport { ContainerBuilder } from '@brainhubeu/sqrs-inversify';\n\n// Assuming CreateNoteCommand, NoteRepository are declared\nclass CreateNoteCommandHandler implements CommandHandler<CreateNoteCommand> {\n  static type = CommandTypes.CreateNote;\n\n  static dependencies: Dependencies<typeof CreateNoteCommandHandler> = [\n    eventBusId,\n    noteRepositoryId,\n  ]\n\n  constructor (\n    private readonly eventBus: EventBus,\n    private readonly noteRepository: NoteRepository,\n  ) {\n  }\n\n  async handle (command: CreateNoteCommand) {\n    const note = new Note(command.text);\n\n    await this.noteRepository.save(note);\n\n    this.eventBus.raise(\n      noteCreatedEvent(note)\n    )\n  }\n}\n\nconst container = new Container();\nconst builder = new ContainerBuilder(container);\n\nbuilder.registerCommandHandler(CreateNoteCommandHandler);\n\n// Or using a module\nconst module = new ContainerModule(bind => {\n  const builder = new ContainerBuilder(bind);\n\n  builder.registerCommandHandler(CreateNoteCommandHandler);\n})\n```\n\nIt can be used with classes that have static field called `dependencies`, e.g.:\n\n```ts\nclass Foo {\n  static dependencies = [];\n}\n```\n\nThe type of dependencies should be `Dependencies` imported from `sqrs` module. This type reflects arguments of the constructor and requires correct order and number of identifiers of type `DependencyIdentifier<T>`, e.g.:\n\n```ts\nimport {\n  Dependencies,\n  depId,\n} from '@brainhubeu/sqrs';\n\ntype Foo = {};\ntype Baz = {};\n\nconst bazId = depId<Baz>('Baz')\nconst fooId = depId<Foo>('Foo')\n\nclass Bar {\n  static dependencies: Dependencies<typeof Bar> = [\n    fooId,\n    bazId,\n  ]\n\n  constructor (\n    foo: Foo,\n    baz: Baz,\n  ) {\n  }\n}\n\n```\n\nWhen you change the order of constructor arguments or their types, dependencies will cause an error guarding the types that are injected.\n\nTo register a type that has `dependencies` static field use `registerType` method.\n\n```ts\nimport { Container } from 'inversify';\nimport { depId } from '@brainhubeu/sqrs';\nimport { ContainerBuilder } from '@brainhubeu/sqrs-inversify';\n\nconst container = new Container();\nconst builder = new ContainerBuilder(container);\n\nconst barId = depId<Bar>('Bar');\n\nbuilder.registerType(barId, Bar);\n```\n\n`ContainerBuilder` exposes methods that allow for easy registration of:\n- command handlers\n- query handlers\n- event handlers\n\nTo register a `CommandHandler` implementation add static fields `dependencies` and `type` to the class. The `type` field represents the type of command that this command handler handles, e.g.\n\n```ts\nclass CreateNoteCommandHandler implements CommandHandler<CreateNoteCommand> {\n  static type = CommandTypes.CreateNote;\n  static dependencies: Dependencies<typeof CreateNoteCommandHandler> = [\n\n  ];\n\n  constructor () {\n  }\n\n  ...\n}\n\n/*\n * same as \n * containerBuilder.registerType(\n *   commandHandlerId(CommandTypes.CreateNote),\n *   CreateNoteCommandHandler\n * )\n */\ncontainerBuilder.registerCommandHandler(CreateNoteCommandHandler)\n```\n\nTo register a `QueryHandler` implementation add static fields `dependencies` and `queryName` to the class. The `queryName` field represents the name of query that this handler handles, e.g.\n\n```ts\nclass GetNotesQueryHandler implements QueryHandler<GetNotesQuery> {\n  static queryName = QueryNames.GetNote;\n  static dependencies: Dependencies<typeof GetNotesQueryHandler> = [\n\n  ];\n\n  constructor () {\n  }\n\n  ...\n}\n\n/*\n * same as \n * containerBuilder.registerType(\n *   queryHandlerId(QueryNames.GetNotes),\n *   GetNotesQueryHandler\n * )\n */\ncontainerBuilder.registerQueryHandler(GetNotesQueryHandler)\n```\n\n\nTo register an `EventHandler` implementation add static fields `dependencies` and `type` to the class. The `type` field represents the type of event that this handler handles or an array of types that this handler handles, e.g.\n\n```ts\nclass NoteCreatedEventHandler implements EventHandler<NoteCreatedEvent> {\n  // Could also be [ EventTypes.NoteCreated ];\n  static type = EventTypes.NoteCreated;\n  static dependencies: Dependencies<typeof GetNotesQueryHandler> = [\n\n  ];\n\n  constructor () {\n  }\n\n  ...\n}\n\n/*\n * same as calling following for each event type\n * containerBuilder.registerType(\n *   eventHandlerId(eventType),\n *   NoteCreatedEventHandler\n * )\n */\ncontainerBuilder.registerEventHandler(NoteCreatedEventHandler)\n```","readmeFilename":"README.md"}