@node-ts/bus-core
Advanced tools
Comparing version 0.1.7 to 0.1.8
@@ -19,2 +19,3 @@ "use strict"; | ||
bindService(bind, bus_symbols_1.BUS_SYMBOLS.HandlerRegistry, handler_1.HandlerRegistry).inSingletonScope(); | ||
bindService(bind, bus_symbols_1.BUS_SYMBOLS.JsonSerializer, serialization_1.JsonSerializer); | ||
}); | ||
@@ -21,0 +22,0 @@ } |
@@ -7,3 +7,4 @@ export declare const BUS_SYMBOLS: { | ||
ApplicationBootstrap: symbol; | ||
JsonSerializer: symbol; | ||
}; | ||
export declare const BUS_INTERNAL_SYMBOLS: {}; |
@@ -8,5 +8,6 @@ "use strict"; | ||
HandlerRegistry: Symbol.for('@node-ts/bus-core/handler-registry'), | ||
ApplicationBootstrap: Symbol.for('@node-ts/bus-core/application-bootstrap') | ||
ApplicationBootstrap: Symbol.for('@node-ts/bus-core/application-bootstrap'), | ||
JsonSerializer: Symbol.for('@node-ts/bus-core/json-serializer') | ||
}; | ||
exports.BUS_INTERNAL_SYMBOLS = {}; | ||
//# sourceMappingURL=bus-symbols.js.map |
@@ -8,1 +8,2 @@ export { BUS_SYMBOLS } from './bus-symbols'; | ||
export * from './serialization'; | ||
export * from './util'; |
@@ -11,2 +11,3 @@ "use strict"; | ||
tslib_1.__exportStar(require("./serialization"), exports); | ||
tslib_1.__exportStar(require("./util"), exports); | ||
//# sourceMappingURL=index.js.map |
@@ -10,3 +10,5 @@ import { Serializer } from './serializer'; | ||
serialize<T extends object>(obj: T): string; | ||
deserialize<T extends object>(val: string, _: ClassConstructor<T>): T; | ||
deserialize<T extends object>(val: string, classConstructor: ClassConstructor<T>): T; | ||
toPlain<T extends object>(obj: T): object; | ||
toClass<T extends object>(obj: object, classConstructor: ClassConstructor<T>): T; | ||
} |
@@ -5,2 +5,3 @@ "use strict"; | ||
const inversify_1 = require("inversify"); | ||
const class_transformer_1 = require("class-transformer"); | ||
/** | ||
@@ -13,7 +14,13 @@ * A very unsafe, basic JSON serializer. This will serialize objects to strings, but will | ||
serialize(obj) { | ||
return JSON.stringify(obj); | ||
return class_transformer_1.serialize(obj); | ||
} | ||
deserialize(val, _) { | ||
return JSON.parse(val); | ||
deserialize(val, classConstructor) { | ||
return class_transformer_1.deserialize(classConstructor, val); | ||
} | ||
toPlain(obj) { | ||
return class_transformer_1.classToPlain(obj); | ||
} | ||
toClass(obj, classConstructor) { | ||
return class_transformer_1.plainToClass(classConstructor, obj); | ||
} | ||
}; | ||
@@ -20,0 +27,0 @@ JsonSerializer = tslib_1.__decorate([ |
{ | ||
"name": "@node-ts/bus-core", | ||
"version": "0.1.7", | ||
"description": "Core bus logic", | ||
"version": "0.1.8", | ||
"description": "A message bus abstraction to build simple distributed applications in Node.", | ||
"main": "./dist/index.js", | ||
@@ -16,5 +16,6 @@ "types": "./dist/index.d.ts", | ||
"dependencies": { | ||
"@node-ts/bus-messages": "^0.1.1", | ||
"@node-ts/bus-messages": "^0.1.2", | ||
"@types/node": "^11.12.2", | ||
"autobind-decorator": "^2.4.0", | ||
"class-transformer": "^0.2.0", | ||
"inversify": "^5.0.1", | ||
@@ -47,3 +48,3 @@ "reflect-metadata": "^0.1.13", | ||
], | ||
"gitHead": "51f10629f589881a5d4d80a62cb5fedf03efa2ec" | ||
"gitHead": "8f5512040833e65e316b9fd04e6206559ada03ef" | ||
} |
@@ -20,2 +20,3 @@ import { ContainerModule, interfaces } from 'inversify' | ||
bindService(bind, BUS_SYMBOLS.HandlerRegistry, HandlerRegistry).inSingletonScope() | ||
bindService(bind, BUS_SYMBOLS.JsonSerializer, JsonSerializer) | ||
}) | ||
@@ -22,0 +23,0 @@ } |
@@ -6,3 +6,4 @@ export const BUS_SYMBOLS = { | ||
HandlerRegistry: Symbol.for('@node-ts/bus-core/handler-registry'), | ||
ApplicationBootstrap: Symbol.for('@node-ts/bus-core/application-bootstrap') | ||
ApplicationBootstrap: Symbol.for('@node-ts/bus-core/application-bootstrap'), | ||
JsonSerializer: Symbol.for('@node-ts/bus-core/json-serializer') | ||
} | ||
@@ -9,0 +10,0 @@ |
@@ -8,1 +8,2 @@ export { BUS_SYMBOLS } from './bus-symbols' | ||
export * from './serialization' | ||
export * from './util' |
@@ -0,5 +1,23 @@ | ||
// tslint:disable:no-magic-numbers Date based tests | ||
import { JsonSerializer } from './json-serializer' | ||
import { Type } from 'class-transformer' | ||
class Contract { | ||
@Type(() => Date) readonly c: Date | ||
testFn: () => void | ||
constructor ( | ||
readonly a: string, | ||
readonly b: number, | ||
c: Date | ||
) { | ||
this.c = c | ||
} | ||
} | ||
describe('JsonSerializer', () => { | ||
let sut: JsonSerializer | ||
const contract = new Contract('a', 1, new Date()) | ||
@@ -14,4 +32,5 @@ beforeEach(() => { | ||
result = sut.serialize({ | ||
string: 'a', | ||
number: 1 | ||
a: 'a', | ||
b: 1, | ||
c: new Date(2000, 2, 1) | ||
}) | ||
@@ -21,3 +40,3 @@ }) | ||
it('should convert an object to a string', () => { | ||
expect(result).toEqual('{"string":"a","number":1}') | ||
expect(result).toEqual('{"a":"a","b":1,"c":"2000-02-29T14:00:00.000Z"}') | ||
}) | ||
@@ -27,12 +46,5 @@ }) | ||
describe('when deserializing', () => { | ||
class Contract { | ||
constructor ( | ||
readonly a: string, | ||
readonly b: number | ||
) { | ||
} | ||
} | ||
let result: Contract | ||
beforeEach(() => { | ||
result = sut.deserialize('{"a":"a","b":1}', Contract) | ||
result = sut.deserialize('{"a":"a","b":1,"c":"2000-02-29T14:00:00.000Z"}', Contract) | ||
}) | ||
@@ -42,4 +54,19 @@ | ||
expect(result).toMatchObject({ a: 'a', b: 1 }) | ||
expect(result.c).toBeDefined() | ||
// tslint:disable-next-line:no-unbound-method Testing presence | ||
expect(result.c.toUTCString).toBeDefined() | ||
expect(result.c.getDate()).toEqual(new Date(2000, 2, 1).getDate()) | ||
}) | ||
}) | ||
describe('when converting typed object to plain', () => { | ||
let result: object | ||
beforeEach(() => { | ||
result = sut.toPlain(contract) | ||
}) | ||
it('should strip out additional fields', () => { | ||
expect(Object.keys(result)).not.toContain('testFn') | ||
}) | ||
}) | ||
}) |
import { injectable } from 'inversify' | ||
import { Serializer } from './serializer' | ||
import { ClassConstructor } from '../util' | ||
import { classToPlain, plainToClass, serialize, deserialize } from 'class-transformer' | ||
@@ -13,8 +14,16 @@ /** | ||
serialize<T extends object> (obj: T): string { | ||
return JSON.stringify(obj) | ||
return serialize(obj) | ||
} | ||
deserialize<T extends object> (val: string, _: ClassConstructor<T>): T { | ||
return JSON.parse(val) as T | ||
deserialize<T extends object> (val: string, classConstructor: ClassConstructor<T>): T { | ||
return deserialize<T> (classConstructor, val) | ||
} | ||
toPlain<T extends object> (obj: T): object { | ||
return classToPlain(obj) | ||
} | ||
toClass<T extends object> (obj: object, classConstructor: ClassConstructor<T>): T { | ||
return plainToClass(classConstructor, obj) | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
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
93212
1823
9
+ Addedclass-transformer@^0.2.0
+ Addedclass-transformer@0.2.3(transitive)
Updated@node-ts/bus-messages@^0.1.2