@superhero/core 1.8.5 → 4.0.0-beta.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (175) hide show
  1. package/README.md +108 -739
  2. package/index.js +654 -54
  3. package/index.test.js +94 -0
  4. package/package.json +17 -31
  5. package/worker.js +12 -0
  6. package/LICENCE +0 -20
  7. package/bootstrap/config.js +0 -7
  8. package/bootstrap/index.js +0 -19
  9. package/bootstrap/locator.js +0 -16
  10. package/cli/config.js +0 -7
  11. package/cli/index.js +0 -49
  12. package/cli/locator.js +0 -17
  13. package/composer/bootstrap/error/schema-not-resolvable.js +0 -10
  14. package/composer/bootstrap/index.js +0 -62
  15. package/composer/bootstrap/locator.js +0 -20
  16. package/composer/config.js +0 -49
  17. package/composer/error/filter-is-not-honering-contract.js +0 -13
  18. package/composer/error/invalid-attribute.js +0 -13
  19. package/composer/error/invalid-collection.js +0 -13
  20. package/composer/error/invalid-schema.js +0 -13
  21. package/composer/error/schema-not-found.js +0 -13
  22. package/composer/error/validator-is-not-honering-contract.js +0 -13
  23. package/composer/error/validator-not-found.js +0 -13
  24. package/composer/filter/boolean/index.js +0 -44
  25. package/composer/filter/boolean/locator.js +0 -11
  26. package/composer/filter/decimal/index.js +0 -38
  27. package/composer/filter/decimal/locator.js +0 -11
  28. package/composer/filter/index.js +0 -10
  29. package/composer/filter/integer/index.js +0 -38
  30. package/composer/filter/integer/locator.js +0 -11
  31. package/composer/filter/json/index.js +0 -23
  32. package/composer/filter/json/locator.js +0 -11
  33. package/composer/filter/schema/error/missing-schema-definition.js +0 -13
  34. package/composer/filter/schema/index.js +0 -49
  35. package/composer/filter/schema/locator.js +0 -17
  36. package/composer/filter/string/index.js +0 -50
  37. package/composer/filter/string/locator.js +0 -11
  38. package/composer/filter/timestamp/index.js +0 -45
  39. package/composer/filter/timestamp/locator.js +0 -11
  40. package/composer/index.js +0 -180
  41. package/composer/locator.js +0 -17
  42. package/composer/validator/boolean/error/invalid.js +0 -13
  43. package/composer/validator/boolean/index.js +0 -17
  44. package/composer/validator/boolean/locator.js +0 -11
  45. package/composer/validator/decimal/error/invalid.js +0 -13
  46. package/composer/validator/decimal/index.js +0 -59
  47. package/composer/validator/decimal/locator.js +0 -11
  48. package/composer/validator/index.js +0 -10
  49. package/composer/validator/integer/error/invalid.js +0 -13
  50. package/composer/validator/integer/index.js +0 -65
  51. package/composer/validator/integer/locator.js +0 -11
  52. package/composer/validator/json/error/invalid.js +0 -13
  53. package/composer/validator/json/index.js +0 -23
  54. package/composer/validator/json/locator.js +0 -11
  55. package/composer/validator/schema/error/invalid.js +0 -13
  56. package/composer/validator/schema/index.js +0 -13
  57. package/composer/validator/schema/locator.js +0 -11
  58. package/composer/validator/string/error/invalid.js +0 -13
  59. package/composer/validator/string/index.js +0 -59
  60. package/composer/validator/string/locator.js +0 -11
  61. package/composer/validator/timestamp/error/invalid.js +0 -13
  62. package/composer/validator/timestamp/index.js +0 -54
  63. package/composer/validator/timestamp/locator.js +0 -11
  64. package/configuration/config.js +0 -7
  65. package/configuration/index.js +0 -23
  66. package/configuration/locator.js +0 -22
  67. package/console/config.js +0 -15
  68. package/console/index.js +0 -23
  69. package/console/locator.js +0 -21
  70. package/console/observer/error/config.js +0 -7
  71. package/console/observer/error/index.js +0 -14
  72. package/console/observer/error/locator.js +0 -17
  73. package/console/observer/info/config.js +0 -7
  74. package/console/observer/info/index.js +0 -14
  75. package/console/observer/info/locator.js +0 -17
  76. package/console/observer/warning/config.js +0 -7
  77. package/console/observer/warning/index.js +0 -14
  78. package/console/observer/warning/locator.js +0 -17
  79. package/core/config.js +0 -21
  80. package/core/error.js +0 -10
  81. package/deepcopy/config.js +0 -7
  82. package/deepcopy/error/failed-to-fast-copy.js +0 -10
  83. package/deepcopy/index.js +0 -18
  84. package/deepcopy/locator.js +0 -11
  85. package/deepfind/config.js +0 -7
  86. package/deepfind/index.js +0 -11
  87. package/deepfind/locator.js +0 -11
  88. package/deepfreeze/config.js +0 -7
  89. package/deepfreeze/index.js +0 -20
  90. package/deepfreeze/locator.js +0 -11
  91. package/deepmerge/config.js +0 -7
  92. package/deepmerge/index.js +0 -42
  93. package/deepmerge/locator.js +0 -11
  94. package/eventbus/bootstrap/error/observer-contract-not-honered.js +0 -10
  95. package/eventbus/bootstrap/index.js +0 -33
  96. package/eventbus/bootstrap/locator.js +0 -20
  97. package/eventbus/config.js +0 -17
  98. package/eventbus/index.js +0 -21
  99. package/eventbus/locator.js +0 -25
  100. package/eventbus/observer.js +0 -9
  101. package/factory.js +0 -55
  102. package/http/request/config.js +0 -7
  103. package/http/request/locator.js +0 -21
  104. package/http/server/config.js +0 -23
  105. package/http/server/dispatcher/chain/error/dispatcher-chain-ended.js +0 -10
  106. package/http/server/dispatcher/chain/index.js +0 -41
  107. package/http/server/dispatcher/chain/locator.js +0 -20
  108. package/http/server/dispatcher/collection/builder/error/dispatcher-can-not-be-resolved.js +0 -10
  109. package/http/server/dispatcher/collection/builder/error/not-honering-dispatcher-contract.js +0 -10
  110. package/http/server/dispatcher/collection/builder/index.js +0 -56
  111. package/http/server/dispatcher/collection/builder/locator.js +0 -20
  112. package/http/server/dispatcher/error/bad-gateway.js +0 -12
  113. package/http/server/dispatcher/error/bad-request.js +0 -12
  114. package/http/server/dispatcher/error/conflict.js +0 -12
  115. package/http/server/dispatcher/error/forbidden.js +0 -12
  116. package/http/server/dispatcher/error/gateway-timeout.js +0 -12
  117. package/http/server/dispatcher/error/index.js +0 -10
  118. package/http/server/dispatcher/error/method-not-allowed.js +0 -12
  119. package/http/server/dispatcher/error/not-implemented.js +0 -12
  120. package/http/server/dispatcher/error/page-not-found.js +0 -12
  121. package/http/server/dispatcher/error/request-timeout.js +0 -12
  122. package/http/server/dispatcher/error/server-error.js +0 -12
  123. package/http/server/dispatcher/error/service-unavailable.js +0 -12
  124. package/http/server/dispatcher/error/unauthorized.js +0 -12
  125. package/http/server/dispatcher/index.js +0 -26
  126. package/http/server/dispatcher/rest.js +0 -75
  127. package/http/server/error/no-endpoint-defined-in-route.js +0 -10
  128. package/http/server/error/view-contract-not-honered.js +0 -10
  129. package/http/server/index.js +0 -195
  130. package/http/server/locator.js +0 -34
  131. package/http/server/request/builder/index.js +0 -53
  132. package/http/server/request/builder/locator.js +0 -20
  133. package/http/server/route/builder/error/dto-invalid-reference.js +0 -10
  134. package/http/server/route/builder/error/routes-invalid-type.js +0 -10
  135. package/http/server/route/builder/index.js +0 -88
  136. package/http/server/route/builder/locator.js +0 -20
  137. package/http/server/session/builder/index.js +0 -34
  138. package/http/server/session/builder/locator.js +0 -11
  139. package/http/server/view/index.js +0 -12
  140. package/http/server/view/json/index.js +0 -17
  141. package/http/server/view/json/locator.js +0 -11
  142. package/http/server/view/locator.js +0 -11
  143. package/http/server/view/stream/index.js +0 -10
  144. package/http/server/view/stream/locator.js +0 -11
  145. package/http/server/view/text/index.js +0 -15
  146. package/http/server/view/text/locator.js +0 -11
  147. package/locator/constituent.js +0 -26
  148. package/locator/error/locator-not-implemented.js +0 -10
  149. package/locator/error/service-undefined.js +0 -10
  150. package/locator/index.js +0 -29
  151. package/path/config.js +0 -7
  152. package/path/index.js +0 -63
  153. package/path/locator.js +0 -11
  154. package/process/bootstrap/index.js +0 -31
  155. package/process/bootstrap/locator.js +0 -17
  156. package/process/config.js +0 -12
  157. package/process/index.js +0 -9
  158. package/process/locator.js +0 -11
  159. package/test/api/config.js +0 -43
  160. package/test/api/endpoint/append-calculation.js +0 -41
  161. package/test/api/endpoint/create-calculation.js +0 -18
  162. package/test/api/middleware/authentication.js +0 -27
  163. package/test/calculator/calculation.js +0 -29
  164. package/test/calculator/config.js +0 -14
  165. package/test/calculator/error/calculation-could-not-be-found.js +0 -13
  166. package/test/calculator/error/invalid-calculation-type.js +0 -13
  167. package/test/calculator/index.js +0 -67
  168. package/test/calculator/locator.js +0 -20
  169. package/test/init.js +0 -2
  170. package/test/logger/config.js +0 -15
  171. package/test/logger/index.js +0 -17
  172. package/test/logger/locator.js +0 -20
  173. package/test/mocha.opts +0 -4
  174. package/test/test.calculation.js +0 -58
  175. package/test/test.logger.js +0 -35
@@ -1,11 +0,0 @@
1
- const HttpViewJson = require('.')
2
-
3
- class HttpViewJsonLocator
4
- {
5
- locate()
6
- {
7
- return new HttpViewJson
8
- }
9
- }
10
-
11
- module.exports = HttpViewJsonLocator
@@ -1,11 +0,0 @@
1
- const HttpView = require('.')
2
-
3
- class HttpViewLocator
4
- {
5
- locate()
6
- {
7
- return new HttpView
8
- }
9
- }
10
-
11
- module.exports = HttpViewLocator
@@ -1,10 +0,0 @@
1
- class HttpViewStream
2
- {
3
- write(output, viewModel, route)
4
- {
5
- output.writeHead(viewModel.meta.status || 200, viewModel.headers)
6
- viewModel.meta.stream.pipe(output)
7
- }
8
- }
9
-
10
- module.exports = HttpViewStream
@@ -1,11 +0,0 @@
1
- const HttpViewStream = require('.')
2
-
3
- class HttpViewStreamLocator
4
- {
5
- locate()
6
- {
7
- return new HttpViewStream
8
- }
9
- }
10
-
11
- module.exports = HttpViewStreamLocator
@@ -1,15 +0,0 @@
1
- class HttpViewText
2
- {
3
- write(output, viewModel)
4
- {
5
- const body = `${viewModel.body}`
6
-
7
- viewModel.headers['Content-Type'] = 'text/plain'
8
- viewModel.headers['Content-Length'] = Buffer.byteLength(body)
9
-
10
- output.writeHead(viewModel.status || 200, viewModel.headers)
11
- output.end(body)
12
- }
13
- }
14
-
15
- module.exports = HttpViewText
@@ -1,11 +0,0 @@
1
- const HttpViewText = require('.')
2
-
3
- class HttpViewTextLocator
4
- {
5
- locate()
6
- {
7
- return new HttpViewText
8
- }
9
- }
10
-
11
- module.exports = HttpViewTextLocator
@@ -1,26 +0,0 @@
1
- const LocatorNotImplementedError = require('./error/locator-not-implemented')
2
-
3
- /**
4
- * For classes that represent a locator constituent of a composite pattern.
5
- *
6
- * @abstract
7
- */
8
- class LocatorConstituent
9
- {
10
- constructor(locator)
11
- {
12
- this.locator = locator
13
- }
14
-
15
- /**
16
- * A factory method for a service
17
- * @returns {*} An instenace of the service that is being located
18
- * @abstract
19
- */
20
- locate()
21
- {
22
- throw new LocatorNotImplementedError('the "locate" method was not overwritten')
23
- }
24
- }
25
-
26
- module.exports = LocatorConstituent
@@ -1,10 +0,0 @@
1
- class LocatorNotImplementedError extends Error
2
- {
3
- constructor(...a)
4
- {
5
- super(...a)
6
- this.code = 'E_LOCATOR_NOT_IMPLEMENTED'
7
- }
8
- }
9
-
10
- module.exports = LocatorNotImplementedError
@@ -1,10 +0,0 @@
1
- class ServiceUndefinedError extends ReferenceError
2
- {
3
- constructor(...a)
4
- {
5
- super(...a)
6
- this.code = 'E_SERVICE_UNDEFINED'
7
- }
8
- }
9
-
10
- module.exports = ServiceUndefinedError
package/locator/index.js DELETED
@@ -1,29 +0,0 @@
1
- const ServiceUndefinedError = require('./error/service-undefined')
2
-
3
- class Locator
4
- {
5
- constructor()
6
- {
7
- this.services = {}
8
- }
9
-
10
- set(name, service)
11
- {
12
- this.services[name] = service
13
- }
14
-
15
- has(name)
16
- {
17
- return name in this.services
18
- }
19
-
20
- locate(service)
21
- {
22
- if(service in this.services)
23
- return this.services[service]
24
-
25
- throw new ServiceUndefinedError(`"${service}" can not be located`)
26
- }
27
- }
28
-
29
- module.exports = Locator
package/path/config.js DELETED
@@ -1,7 +0,0 @@
1
- module.exports =
2
- {
3
- locator:
4
- {
5
- 'path' : __dirname
6
- }
7
- }
package/path/index.js DELETED
@@ -1,63 +0,0 @@
1
- const path = require('path')
2
-
3
- class Path
4
- {
5
- constructor()
6
- {
7
- const
8
- filename = require.main.filename,
9
- dirname = this.dirname(filename)
10
-
11
- this.main = { filename, dirname }
12
- }
13
-
14
- /**
15
- * @see require.resolve
16
- */
17
- isResolvable(filename)
18
- {
19
- try
20
- {
21
- require.resolve(filename)
22
- return true
23
- }
24
- catch (error)
25
- {
26
- return false
27
- }
28
- }
29
-
30
- /**
31
- * @see path.dirname
32
- */
33
- dirname(filename)
34
- {
35
- return path.dirname(filename)
36
- }
37
-
38
- /**
39
- * @see path.normalize
40
- */
41
- normalize(filename)
42
- {
43
- return path.normalize(filename)
44
- }
45
-
46
- /**
47
- * @see path.extname
48
- */
49
- extension(filename)
50
- {
51
- return path.extname(filename)
52
- }
53
-
54
- /**
55
- * @see path.isAbsolute
56
- */
57
- isAbsolute(filename)
58
- {
59
- return path.isAbsolute(filename)
60
- }
61
- }
62
-
63
- module.exports = Path
package/path/locator.js DELETED
@@ -1,11 +0,0 @@
1
- const Path = require('.')
2
-
3
- class PathLocator
4
- {
5
- locate()
6
- {
7
- return new Path
8
- }
9
- }
10
-
11
- module.exports = PathLocator
@@ -1,31 +0,0 @@
1
- class EventBusBootstrap
2
- {
3
- constructor(eventbus)
4
- {
5
- this.eventbus = eventbus
6
- }
7
-
8
- bootstrap()
9
- {
10
- process.on('unhandledRejection', this.onError.bind(this))
11
- process.on('uncaughtException', this.onError.bind(this))
12
- }
13
-
14
- onError(error, rejectedPromise)
15
- {
16
- if(rejectedPromise && rejectedPromise.domain)
17
- {
18
- rejectedPromise.domain.emit('error', error)
19
- }
20
- else if(process.domain)
21
- {
22
- process.domain.emit('error', error)
23
- }
24
- else
25
- {
26
- this.eventbus.emit('core.error', error)
27
- }
28
- }
29
- }
30
-
31
- module.exports = EventBusBootstrap
@@ -1,17 +0,0 @@
1
- const ProcessBootstrap = require('.')
2
-
3
- class ProcessBootstrapLocator
4
- {
5
- constructor(locator)
6
- {
7
- this.locator = locator
8
- }
9
-
10
- locate()
11
- {
12
- const eventbus = this.locator.locate('eventbus')
13
- return new ProcessBootstrap(eventbus)
14
- }
15
- }
16
-
17
- module.exports = ProcessBootstrapLocator
package/process/config.js DELETED
@@ -1,12 +0,0 @@
1
- module.exports =
2
- {
3
- bootstrap:
4
- {
5
- 'process' : 'process/bootstrap'
6
- },
7
- locator:
8
- {
9
- 'process' : __dirname,
10
- 'process/bootstrap' : __dirname + '/bootstrap'
11
- }
12
- }
package/process/index.js DELETED
@@ -1,9 +0,0 @@
1
- class Process
2
- {
3
- exit(...a)
4
- {
5
- process.exit(...a)
6
- }
7
- }
8
-
9
- module.exports = Process
@@ -1,11 +0,0 @@
1
- const Process = require('.')
2
-
3
- class ProcessLocator
4
- {
5
- locate()
6
- {
7
- return new Process
8
- }
9
- }
10
-
11
- module.exports = ProcessLocator
@@ -1,43 +0,0 @@
1
- module.exports =
2
- {
3
- http:
4
- {
5
- server:
6
- {
7
- routes:
8
- {
9
- 'create-calculation':
10
- {
11
- url : '/calculations',
12
- method : 'post',
13
- endpoint: 'api/endpoint/create-calculation',
14
- view : 'http/server/view/json'
15
- },
16
- 'authentication':
17
- {
18
- middleware :
19
- [
20
- 'api/middleware/authentication'
21
- ]
22
- },
23
- 'append-calculation':
24
- {
25
- url : '/calculations/.+',
26
- method : 'put',
27
- endpoint: 'api/endpoint/append-calculation',
28
- view : 'http/server/view/json',
29
- dto :
30
- {
31
- 'id' : { 'url' : 2 },
32
- 'type' : { 'body' : 'type' },
33
- 'value' : { 'body' : 'value' }
34
- }
35
- }
36
- }
37
- }
38
- },
39
- authentication:
40
- {
41
- apikey : 'ABC123456789'
42
- }
43
- }
@@ -1,41 +0,0 @@
1
- const
2
- Dispatcher = require('../../../http/server/dispatcher'),
3
- PageNotFoundError = require('../../../http/server/dispatcher/error/page-not-found'),
4
- BadRequestError = require('../../../http/server/dispatcher/error/bad-request')
5
-
6
- /**
7
- * @extends {@superhero/core/http/server/dispatcher}
8
- */
9
- class AppendCalculationEndpoint extends Dispatcher
10
- {
11
- dispatch()
12
- {
13
- const
14
- calculator = this.locator.locate('calculator'),
15
- composer = this.locator.locate('composer'),
16
- calculation = composer.compose('calculation', this.route.dto),
17
- result = calculator.appendToCalculation(calculation)
18
-
19
- this.view.body.result = result
20
- }
21
-
22
- onError(error)
23
- {
24
- switch(error)
25
- {
26
- case 'E_CALCULATION_COULD_NOT_BE_FOUND':
27
- throw new PageNotFoundError('Calculation could not be found')
28
-
29
- case 'E_INVALID_CALCULATION_TYPE':
30
- throw new BadRequestError(`Unrecognized type: "${this.route.dto.type}"`)
31
-
32
- case 'E_COMPOSER_INVALID_ATTRIBUTE':
33
- throw new BadRequestError(error.message)
34
-
35
- default:
36
- throw error
37
- }
38
- }
39
- }
40
-
41
- module.exports = AppendCalculationEndpoint
@@ -1,18 +0,0 @@
1
- const Dispatcher = require('../../../http/server/dispatcher')
2
-
3
- /**
4
- * @extends {@superhero/core/http/server/dispatcher}
5
- */
6
- class CreateCalculationEndpoint extends Dispatcher
7
- {
8
- dispatch()
9
- {
10
- const
11
- calculator = this.locator.locate('calculator'),
12
- calculationId = calculator.createCalculation()
13
-
14
- this.view.body.id = calculationId
15
- }
16
- }
17
-
18
- module.exports = CreateCalculationEndpoint
@@ -1,27 +0,0 @@
1
- const
2
- Dispatcher = require('../../../http/server/dispatcher'),
3
- Unauthorized = require('../../../http/server/dispatcher/error/unauthorized')
4
-
5
- /**
6
- * @extends {@superhero/core/http/server/dispatcher}
7
- */
8
- class AuthenticationMiddleware extends Dispatcher
9
- {
10
- async dispatch(next)
11
- {
12
- const
13
- configuration = this.locator.locate('configuration'),
14
- apikey = this.request.headers['api-key']
15
-
16
- if(apikey === configuration.find('authentication.apikey'))
17
- {
18
- await next()
19
- }
20
- else
21
- {
22
- throw new Unauthorized('You are not authorized to access the requested resource')
23
- }
24
- }
25
- }
26
-
27
- module.exports = AuthenticationMiddleware
@@ -1,29 +0,0 @@
1
- /**
2
- * @typedef {Object} CalculatorCalculation
3
- * @property {number} id
4
- * @property {string} type
5
- * @property {number} value
6
- */
7
- const dto =
8
- {
9
- 'id':
10
- {
11
- 'type' : 'integer',
12
- 'unsigned': true
13
- },
14
- 'type':
15
- {
16
- 'type': 'string',
17
- 'enum':
18
- [
19
- 'addition',
20
- 'subtraction'
21
- ]
22
- },
23
- 'value':
24
- {
25
- 'type': 'decimal'
26
- }
27
- }
28
-
29
- module.exports = dto
@@ -1,14 +0,0 @@
1
- module.exports =
2
- {
3
- composer:
4
- {
5
- schema:
6
- {
7
- 'calculation' : __dirname + '/calculation'
8
- }
9
- },
10
- locator:
11
- {
12
- 'calculator' : __dirname
13
- }
14
- }
@@ -1,13 +0,0 @@
1
- /**
2
- * @extends {Error}
3
- */
4
- class CalculationCouldNotBeFoundError extends Error
5
- {
6
- constructor(...args)
7
- {
8
- super(...args)
9
- this.code = 'E_CALCULATION_COULD_NOT_BE_FOUND'
10
- }
11
- }
12
-
13
- module.exports = CalculationCouldNotBeFoundError
@@ -1,13 +0,0 @@
1
- /**
2
- * @extends {Error}
3
- */
4
- class InvalidCalculationTypeError extends Error
5
- {
6
- constructor(...args)
7
- {
8
- super(...args)
9
- this.code = 'E_INVALID_CALCULATION_TYPE'
10
- }
11
- }
12
-
13
- module.exports = InvalidCalculationTypeError
@@ -1,67 +0,0 @@
1
- const
2
- CalculationCouldNotBeFoundError = require('./error/calculation-could-not-be-found'),
3
- InvalidCalculationTypeError = require('./error/invalid-calculation-type')
4
-
5
- /**
6
- * Calculator service, manages calculations
7
- */
8
- class Calculator
9
- {
10
- /**
11
- * @param {@superhero/eventbus} eventbus
12
- */
13
- constructor(eventbus)
14
- {
15
- this.eventbus = eventbus
16
- this.calculations = []
17
- }
18
-
19
- /**
20
- * @returns {number} the id of the created calculation
21
- */
22
- createCalculation()
23
- {
24
- const id = this.calculations.push(0)
25
- this.eventbus.emit('calculator.calculation-created', { id })
26
- return id
27
- }
28
-
29
- /**
30
- * @throws {E_CALCULATION_COULD_NOT_BE_FOUND}
31
- * @throws {E_INVALID_CALCULATION_TYPE}
32
- *
33
- * @param {CalculatorCalculation} dto
34
- *
35
- * @returns {number} the result of the calculation
36
- */
37
- appendToCalculation({ id, type, value })
38
- {
39
- if(id < 1
40
- || id > this.calculations.length)
41
- {
42
- throw new CalculationCouldNotBeFoundError(`Id out of range: "${id}/${this.calculations.length}"`)
43
- }
44
-
45
- switch(type)
46
- {
47
- case 'addition':
48
- {
49
- const result = this.calculations[id - 1] += value
50
- this.eventbus.emit('calculator.calculation-appended', { id, type, result })
51
- return result
52
- }
53
- case 'subtraction':
54
- {
55
- const result = this.calculations[id - 1] -= value
56
- this.eventbus.emit('calculator.calculation-appended', { id, type, result })
57
- return result
58
- }
59
- default:
60
- {
61
- throw new InvalidCalculationTypeError(`Unrecognized type used for calculation: "${type}"`)
62
- }
63
- }
64
- }
65
- }
66
-
67
- module.exports = Calculator
@@ -1,20 +0,0 @@
1
- const
2
- Calculator = require('.'),
3
- LocatorConstituent = require('../../locator/constituent')
4
-
5
- /**
6
- * @extends {@superhero/core/locator/constituent}
7
- */
8
- class CalculatorLocator extends LocatorConstituent
9
- {
10
- /**
11
- * @returns {Calculator}
12
- */
13
- locate()
14
- {
15
- const eventbus = this.locator.locate('eventbus')
16
- return new Calculator(eventbus)
17
- }
18
- }
19
-
20
- module.exports = CalculatorLocator
package/test/init.js DELETED
@@ -1,2 +0,0 @@
1
- require.main.filename = __filename
2
- require.main.dirname = __dirname
@@ -1,15 +0,0 @@
1
- module.exports =
2
- {
3
- eventbus:
4
- {
5
- observers:
6
- {
7
- 'calculator.calculation-created' : [ 'logger' ],
8
- 'calculator.calculation-appended' : [ 'logger' ]
9
- }
10
- },
11
- locator:
12
- {
13
- 'logger' : __dirname
14
- }
15
- }
@@ -1,17 +0,0 @@
1
- /**
2
- * @implements {@superhero/eventbus/observer}
3
- */
4
- class Logger
5
- {
6
- constructor(eventbus)
7
- {
8
- this.eventbus = eventbus
9
- }
10
-
11
- observe(event)
12
- {
13
- this.eventbus.emit('logger.logged-event', event)
14
- }
15
- }
16
-
17
- module.exports = Logger
@@ -1,20 +0,0 @@
1
- const
2
- Logger = require('.'),
3
- LocatorConstituent = require('../../locator/constituent')
4
-
5
- /**
6
- * @extends {@superhero/core/locator/constituent}
7
- */
8
- class LoggerLocator extends LocatorConstituent
9
- {
10
- /**
11
- * @returns {Logger}
12
- */
13
- locate()
14
- {
15
- const eventbus = this.locator.locate('eventbus')
16
- return new Logger(eventbus)
17
- }
18
- }
19
-
20
- module.exports = LoggerLocator