{"_id":"@bakerstreet-industries/bus-class-serializer","_rev":"1-b67c927748e9ef4ef93a6c41347d5205","name":"@bakerstreet-industries/bus-class-serializer","dist-tags":{"latest":"1.0.12"},"versions":{"1.0.12":{"name":"@bakerstreet-industries/bus-class-serializer","version":"1.0.12","description":"A JSON serializer for @node-ts/bus based on class-transformer for strong marshalling of messages","homepage":"https://github.com/node-ts/bus#readme","license":"MIT","repository":{"type":"git","url":"git+https://github.com/bakerstreet-industries/bus.git"},"scripts":{"clean":"rm -rf dist","build":"tsc --project tsconfig.json --declaration","build:watch":"yarn run build --incremental --watch --preserveWatchOutput","lint":"tslint --project tsconfig.json 'src/**/*.ts'","lint:fix":"yarn lint --fix"},"publishConfig":{"access":"public"},"devDependencies":{"@node-ts/bus-core":"^1.0.12","class-transformer":"^0.3.1","reflect-metadata":"^0.1.13"},"peerDependencies":{"@node-ts/bus-core":"^1.0.0-alpha.0","class-transformer":"^0.3.1"},"keywords":["serializer","esb","redis","typescript","enterprise integration patterns","bus","messaging","microservices","distributed systems","framework","enterprise framework","CQRS","ES","NServiceBus","Mule ESB"],"gitHead":"22878835e97f47c5d0cb2aac8b222a0765e1e8fc","bugs":{"url":"https://github.com/bakerstreet-industries/bus/issues"},"_id":"@bakerstreet-industries/bus-class-serializer@1.0.12","_nodeVersion":"14.18.1","_npmVersion":"lerna/4.0.0/node@v14.18.1+arm64 (darwin)","dist":{"integrity":"sha512-uG6qVzS2/qLIHB0QVgILwb4Sz7BDJ1XG1EdDsfMC/fwLLBjMXbKNTR49+CZhnVLY6VPSDfiopCqLAceTCvHP8w==","shasum":"e81567843c5a2ee080089fd6c7ea5e679e34a24a","tarball":"https://registry.npmjs.org/@bakerstreet-industries/bus-class-serializer/-/bus-class-serializer-1.0.12.tgz","fileCount":14,"unpackedSize":10384,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJiB+9iCRA9TVsSAnZWagAAdgoP/1DgXeqMR7pWfSBR7fsZ\nJhzlxbvriMYGD/sxwYNuvRqio4W9vGIw4T+Bzl+RR7icf1hVZ5UUR25LIIhf\nR20ApLFJ0TxApbxUGAVt/WuxRENcYPIAPukXJqNFCsmF5FPul+hRZT8eaQy0\nwJwNcaM1vfn2jMN7J11tQWv9fZLEdMTLAPfjWRK81vIPruzQMjsfuVSqSLKU\nJ55QrvO0+OMjgy4spF1KXI8PnP9c57wpNvnHqTj0Sd5az+NEY5xH07tcACEt\nk2ZJtL3YFMZctiKPXTYpvrJcIAIHH6JOUpt8yhJZA0B1x5bPqZwF//mYRkj2\n+021N+5Qa02CM/exwdiOLvTHUqeLb/bYJbgeFUwlnrZ8D1/90fgXE2DEyHWG\n1GUY1tbj+qn3s5bEZ89+/Z+Dgp3PAJqRXj+yIw9lcDY6qB5VTFxoFiOiM25C\n2EUvBWSXJKFrMeRYE2WwB4qhcEzqv+oWKmCGyoaln0S3lMEpSZJTzLihOul6\nmk3Ix4EF/YHwlp2UyyZczgxoqWIUhzPo+/e+NX2AyQ9Da7N6q/oWJgUeeoFd\nuDkTiB6TeaX9xJm/k46ESi8YGzo2GKsxxVny2F4RdQSwLMEngkHbjC6O5rib\nyuUtjv1e93MZ3Z1IZs95Ffe33AHCMJFl6WCFyV15cv7woPUqenVtrQvwVstK\nEqV3\r\n=kuua\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIFmV+7QPWVT9QD0xwSTDBotdZ53uuB243KVdN0xBSVVdAiBn9WvWeXBtk8gDg1AdHjrlvAnKlesZ8N/+TDnpx1FNuQ=="}]},"_npmUser":{"name":"roustalski","email":"russ@bakerstreet.industries"},"directories":{},"maintainers":[{"name":"roustalski","email":"russ@bakerstreet.industries"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/bus-class-serializer_1.0.12_1644687202386_0.4559637739832336"},"_hasShrinkwrap":false}},"time":{"created":"2022-02-12T17:33:22.333Z","1.0.12":"2022-02-12T17:33:22.516Z","modified":"2022-04-04T17:32:07.102Z"},"maintainers":[{"name":"roustalski","email":"russ@bakerstreet.industries"}],"description":"A JSON serializer for @node-ts/bus based on class-transformer for strong marshalling of messages","homepage":"https://github.com/node-ts/bus#readme","keywords":["serializer","esb","redis","typescript","enterprise integration patterns","bus","messaging","microservices","distributed systems","framework","enterprise framework","CQRS","ES","NServiceBus","Mule ESB"],"repository":{"type":"git","url":"git+https://github.com/bakerstreet-industries/bus.git"},"bugs":{"url":"https://github.com/bakerstreet-industries/bus/issues"},"license":"MIT","readme":"# `@node-ts/bus-class-serializer`\n\nA JSON-based serializer for [@node-ts/bus](https://bus.node-ts.com) that deserializes into strong types. This is a preferred alternative to the default serializer that does not support this.\n\n## Installation\n\nInstall this package and its dependencies\n\n```sh\nnpm i reflect-metadata class-transformer @node-ts/bus-class-serializer\n```\n\nConfigure your bus to use the serializer:\n\n```typescript\nimport { ClassSerializer } from '@node-ts/bus-class-serializer'\n\nawait Bus\n  .configure()\n  .withSerializer(new ClassSerializer())\n  .initialize()\n```\n\n**Note** This package relies on [class transformer](https://www.npmjs.com/package/class-transformer) that requires [reflect-metadata](https://www.npmjs.com/package/reflect-metadata) to be installed and called at the start of your application before any other imports. Please follow their guides on how to configure your app and contracts to serialize correctly.\n\n## Why?\n\nConsider the following message:\n\n```typescript\nclass Update extends Command {\n  constructor (\n    readonly date: Date\n  ) {}\n}\n```\n\nWhen serialized/deserialized this will become a plain object with no date functions on the property:\n\n```typescript\nconst receivedMessage = JSON.parse(JSON.stringify(new Update(new Date())))\nreceivedMessage.getDate() // Error - getDate is undefined\n```\n\nAlthough we could manually fix and assign the date in the handle, this is tedious and adds unecessary code. Instead messages should be holistically deserialized to strong type at the boundaries of the system. \n\nUsing this serializer, a minor change to the contract is made:\n\n```typescript\nclass Update extends Command {\n  @Type(() => Date) readonly date: Date\n  constructor (\n    date: Date\n  ) {\n    this.date = date\n  }\n}\n```\n\nWhen this is deserialized, the date should be an actual `Date`:\n\n```typescript\nconst serializer = new ClassSerializer()\nconst receivedMessage = serializer.deserialize(serializer.serialize(new Update(new Date())), Update)\nreceivedMessage.getDate() // Success - a date value\n```\n","readmeFilename":"README.md"}