@superhero/core 1.8.4 → 4.0.0-beta.1

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 -34
  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,38 +0,0 @@
1
- /**
2
- * @implements {ComposerFilter}
3
- */
4
- class ComposerFilterInteger
5
- {
6
- filter(options, data)
7
- {
8
- return options.collection
9
- ? this.filterCollection(data)
10
- : this.filterSingle(data)
11
- }
12
-
13
- filterCollection(data)
14
- {
15
- if(!Array.isArray(data))
16
- return data
17
-
18
- const collection = []
19
-
20
- for(const item of data)
21
- {
22
- const filtered = this.filterSingle(item)
23
- collection.push(filtered)
24
- }
25
-
26
- return collection
27
- }
28
-
29
- filterSingle(data)
30
- {
31
- if(isNaN(data) === false)
32
- return +data
33
-
34
- return data
35
- }
36
- }
37
-
38
- module.exports = ComposerFilterInteger
@@ -1,11 +0,0 @@
1
- const ComposerFilterInteger = require('.')
2
-
3
- class ComposerFilterIntegerLocator
4
- {
5
- locate()
6
- {
7
- return new ComposerFilterInteger
8
- }
9
- }
10
-
11
- module.exports = ComposerFilterIntegerLocator
@@ -1,23 +0,0 @@
1
- /**
2
- * @implements {ComposerFilter}
3
- */
4
- class ComposerFilterJson
5
- {
6
- filter(options, data)
7
- {
8
- try
9
- {
10
- return options.stringified
11
- ? JSON.stringify(data, null, options.indentation)
12
- : data
13
- }
14
- catch(error)
15
- {
16
- // it's not up to the filter to validate
17
- // if we can't filter the data, then we simply pass the data forward
18
- return data
19
- }
20
- }
21
- }
22
-
23
- module.exports = ComposerFilterJson
@@ -1,11 +0,0 @@
1
- const ComposerFilterString = require('.')
2
-
3
- class ComposerFilterStringLocator
4
- {
5
- locate()
6
- {
7
- return new ComposerFilterString
8
- }
9
- }
10
-
11
- module.exports = ComposerFilterStringLocator
@@ -1,13 +0,0 @@
1
- /**
2
- * @extends {Error}
3
- */
4
- class MissingSchemaDefinitionError extends Error
5
- {
6
- constructor(...a)
7
- {
8
- super(...a)
9
- this.code = 'E_MISSING_SCHEMA_DEFINITION'
10
- }
11
- }
12
-
13
- module.exports = MissingSchemaDefinitionError
@@ -1,49 +0,0 @@
1
- const MissingSchemaDefinitionError = require('./error/missing-schema-definition')
2
- /**
3
- * @implements {ComposerFilter}
4
- */
5
- class ComposerFilterSchema
6
- {
7
- constructor(composer)
8
- {
9
- this.composer = composer
10
- }
11
-
12
- filter(options, data)
13
- {
14
- return options.collection
15
- ? this.filterCollection(options, data)
16
- : this.filterSingle(options, data)
17
- }
18
-
19
- filterCollection(options, data)
20
- {
21
- if(!Array.isArray(data))
22
- return data
23
-
24
- const collection = []
25
-
26
- for(const item of data)
27
- {
28
- const filtered = this.filterSingle(options, item)
29
- collection.push(filtered)
30
- }
31
-
32
- return collection
33
- }
34
-
35
- filterSingle(options, data)
36
- {
37
- if(typeof options.schema === 'string')
38
- {
39
- return this.composer.compose(options.schema, data)
40
- }
41
- else
42
- {
43
- const msg = `Expected the attribute "schema" to define what type/schema to filter by`
44
- throw new MissingSchemaDefinitionError(msg)
45
- }
46
- }
47
- }
48
-
49
- module.exports = ComposerFilterSchema
@@ -1,17 +0,0 @@
1
- const ComposerFilterSchema = require('.')
2
-
3
- class ComposerFilterSchemaLocator
4
- {
5
- constructor(locator)
6
- {
7
- this.locator = locator
8
- }
9
-
10
- locate()
11
- {
12
- const composer = this.locator.locate('composer')
13
- return new ComposerFilterSchema(composer)
14
- }
15
- }
16
-
17
- module.exports = ComposerFilterSchemaLocator
@@ -1,50 +0,0 @@
1
- /**
2
- * @implements {ComposerFilter}
3
- */
4
- class ComposerFilterString
5
- {
6
- filter(options, data)
7
- {
8
- return options.collection
9
- ? this.filterCollection(options, data)
10
- : this.filterSingle(options, data)
11
- }
12
-
13
- filterCollection(options, data)
14
- {
15
- if(!Array.isArray(data))
16
- return data
17
-
18
- const collection = []
19
-
20
- for(const item of data)
21
- {
22
- const filtered = this.filterSingle(options, item)
23
- collection.push(filtered)
24
- }
25
-
26
- return collection
27
- }
28
-
29
- filterSingle(options, data)
30
- {
31
- if(typeof data === 'number')
32
- data = `${data}`
33
-
34
- if(typeof data === 'boolean')
35
- data = `${data}`
36
-
37
- if(typeof data === 'string')
38
- {
39
- if(options.uppercase)
40
- data = data.toUpperCase()
41
-
42
- if(options.lowercase)
43
- data = data.toLowerCase()
44
- }
45
-
46
- return data
47
- }
48
- }
49
-
50
- module.exports = ComposerFilterString
@@ -1,11 +0,0 @@
1
- const ComposerFilterString = require('.')
2
-
3
- class ComposerFilterStringLocator
4
- {
5
- locate()
6
- {
7
- return new ComposerFilterString
8
- }
9
- }
10
-
11
- module.exports = ComposerFilterStringLocator
@@ -1,45 +0,0 @@
1
- /**
2
- * @implements {ComposerFilter}
3
- */
4
- class ComposerFilterTimestamp
5
- {
6
- filter(options, data)
7
- {
8
- return options.collection
9
- ? this.filterCollection(options, data)
10
- : this.filterSingle(options, data)
11
- }
12
-
13
- filterCollection(options, data)
14
- {
15
- if(!Array.isArray(data))
16
- return data
17
-
18
- const collection = []
19
-
20
- for(const item of data)
21
- {
22
- const filtered = this.filterSingle(options, item)
23
- collection.push(filtered)
24
- }
25
-
26
- return collection
27
- }
28
-
29
- filterSingle(options, data)
30
- {
31
- const intData = parseInt(data)
32
- if(intData == data)
33
- data = intData
34
-
35
- if(options.utc)
36
- data = new Date(data).toUTCString()
37
-
38
- if(options.json)
39
- data = new Date(data).toJSON()
40
-
41
- return data
42
- }
43
- }
44
-
45
- module.exports = ComposerFilterTimestamp
@@ -1,11 +0,0 @@
1
- const ComposerFilterTimestamp = require('.')
2
-
3
- class ComposerFilterTimestampLocator
4
- {
5
- locate()
6
- {
7
- return new ComposerFilterTimestamp
8
- }
9
- }
10
-
11
- module.exports = ComposerFilterTimestampLocator
package/composer/index.js DELETED
@@ -1,180 +0,0 @@
1
- const
2
- InvalidAttributeError = require('./error/invalid-attribute'),
3
- InvalidCollectionError = require('./error/invalid-collection'),
4
- InvalidSchemaError = require('./error/invalid-schema'),
5
- SchemaNotFoundError = require('./error/schema-not-found'),
6
- FilterIsNotHoneringContractError = require('./error/filter-is-not-honering-contract'),
7
- ValidatorIsNotHoneringContractError = require('./error/validator-is-not-honering-contract'),
8
- ValidatorNotFoundError = require('./error/validator-not-found')
9
-
10
- class Composer
11
- {
12
- constructor(deepmerge)
13
- {
14
- this.deepmerge = deepmerge
15
- this.schemas = {}
16
- this.filters = {}
17
- this.validators = {}
18
- }
19
-
20
- /**
21
- * @param {string} name
22
- * @param {...Object} dto
23
- *
24
- * @throws {E_SCHEMA_NOT_FOUND}
25
- * @throws {E_VALIDATOR_NOT_FOUND}
26
- * @throws {E_COMPOSER_INVALID_ATTRIBUTE}
27
- *
28
- * @returns {Object}
29
- */
30
- compose(name, ...dto)
31
- {
32
- if(name in this.schemas === false)
33
- {
34
- const msg = `Schema: "${name}" not found`
35
- throw new SchemaNotFoundError(msg)
36
- }
37
-
38
- dto = this.deepmerge.merge({}, ...dto)
39
-
40
- const
41
- schema = this.schemas[name],
42
- output = {}
43
-
44
- for(const attribute in schema)
45
- {
46
- const options = schema[attribute]
47
-
48
- output[attribute] = dto[attribute]
49
-
50
- if('default' in options
51
- && output[attribute] === undefined)
52
- {
53
- output[attribute] = options.default
54
- }
55
-
56
- // if optional, and undefined or null, then we don't need to filter or validate
57
- if(options.optional === true
58
- && output[attribute] === undefined)
59
- {
60
- delete output[attribute]
61
- continue
62
- }
63
-
64
- if(options.nullable === true
65
- && output[attribute] === null)
66
- {
67
- continue
68
- }
69
-
70
- // Filtering attributes if a filter has been defined for the type
71
- if(options.type in this.filters)
72
- {
73
- const filter = this.filters[options.type]
74
- output[attribute] = filter.filter(options, output[attribute])
75
- }
76
-
77
- // Validating type
78
- if(options.type in this.validators === false)
79
- {
80
- const msg = `Validator: "${options.type}" not found`
81
- throw new ValidatorNotFoundError(msg)
82
- }
83
-
84
- try
85
- {
86
- const validator = this.validators[options.type]
87
-
88
- if(options.collection)
89
- {
90
- if(!Array.isArray(output[attribute]))
91
- {
92
- const msg = `Invalid type: "${typeof output[attribute]}", array expected`
93
- throw new InvalidCollectionError(msg)
94
- }
95
-
96
- for(const item of output[attribute])
97
- {
98
- validator.valid(options, item)
99
- }
100
- }
101
- else
102
- {
103
- validator.valid(options, output[attribute])
104
- }
105
- }
106
- catch(error)
107
- {
108
- const msg = `Invalid attribute: "${attribute}", error: ${error.message}`
109
- throw new InvalidAttributeError(msg)
110
- }
111
- }
112
-
113
- return output
114
- }
115
-
116
- /**
117
- * @param {string} schemaName
118
- * @param {Object} schema
119
- * @throws {E_COMPOSER_INVALID_SCHEMA}
120
- */
121
- addSchema(schemaName, schema)
122
- {
123
- if(typeof schema !== 'object')
124
- {
125
- const msg = `Schema "${schemaName}" must be an object`
126
- throw new InvalidSchemaError(msg)
127
- }
128
-
129
- for(const attribute in schema)
130
- {
131
- if(typeof schema[attribute].type !== 'string')
132
- {
133
- const msg = `Attribute "${attribute}" does not have a type defined`
134
- throw new InvalidSchemaError(msg)
135
- }
136
-
137
- if('enum' in schema[attribute] && !Array.isArray(schema[attribute].enum))
138
- {
139
- const msg = `Attribute "${attribute}" enum must be an array`
140
- throw new InvalidSchemaError(msg)
141
- }
142
- }
143
-
144
- this.schemas[schemaName] = schema
145
- }
146
-
147
- /**
148
- * @param {string} filterName
149
- * @param {ComposerFilter} filter
150
- * @throws {E_FILTER_IS_NOT_HONERING_CONTRACT}
151
- */
152
- addFilter(filterName, filter)
153
- {
154
- if(typeof filter.filter !== 'function')
155
- {
156
- const msg = `Filter "${filterName}" not honering contract`
157
- throw new FilterIsNotHoneringContractError(msg)
158
- }
159
-
160
- this.filters[filterName] = filter
161
- }
162
-
163
- /**
164
- * @param {string} validatorName
165
- * @param {ComposerValidator} validator
166
- * @throws {E_VALIDATOR_IS_NOT_HONERING_CONTRACT}
167
- */
168
- addValidator(validatorName, validator)
169
- {
170
- if(typeof validator.valid !== 'function')
171
- {
172
- const msg = `Validator "${validatorName}" not honering contract`
173
- throw new ValidatorIsNotHoneringContractError(msg)
174
- }
175
-
176
- this.validators[validatorName] = validator
177
- }
178
- }
179
-
180
- module.exports = Composer
@@ -1,17 +0,0 @@
1
- const Composer = require('.')
2
-
3
- class ComposerLocator
4
- {
5
- constructor(locator)
6
- {
7
- this.locator = locator
8
- }
9
-
10
- locate()
11
- {
12
- const deepmerge = this.locator.locate('deepmerge')
13
- return new Composer(deepmerge)
14
- }
15
- }
16
-
17
- module.exports = ComposerLocator
@@ -1,13 +0,0 @@
1
- /**
2
- * @extends {Error}
3
- */
4
- class InvalidBooleanError extends Error
5
- {
6
- constructor(...a)
7
- {
8
- super(...a)
9
- this.code = 'E_INVALID_BOOLEAN'
10
- }
11
- }
12
-
13
- module.exports = InvalidBooleanError
@@ -1,17 +0,0 @@
1
- const InvalidBooleanError = require('./error/invalid')
2
- /**
3
- * @implements {ComposerValidator}
4
- */
5
- class ComposerValidatorBoolean
6
- {
7
- valid(options, data)
8
- {
9
- if(typeof data !== 'boolean')
10
- {
11
- const msg = `Invalid type: "${typeof data}", boolean expected`
12
- throw new InvalidBooleanError(msg)
13
- }
14
- }
15
- }
16
-
17
- module.exports = ComposerValidatorBoolean
@@ -1,11 +0,0 @@
1
- const ComposerValidatorBoolean = require('.')
2
-
3
- class ComposerValidatorBooleanLocator
4
- {
5
- locate()
6
- {
7
- return new ComposerValidatorBoolean
8
- }
9
- }
10
-
11
- module.exports = ComposerValidatorBooleanLocator
@@ -1,13 +0,0 @@
1
- /**
2
- * @extends {Error}
3
- */
4
- class InvalidDecimalError extends Error
5
- {
6
- constructor(...a)
7
- {
8
- super(...a)
9
- this.code = 'E_INVALID_DECIMAL'
10
- }
11
- }
12
-
13
- module.exports = InvalidDecimalError
@@ -1,59 +0,0 @@
1
- const InvalidDecimalError = require('./error/invalid')
2
- /**
3
- * @implements {ComposerValidator}
4
- */
5
- class ComposerValidatorDecimal
6
- {
7
- valid(options, data)
8
- {
9
- if(typeof data !== 'number')
10
- {
11
- const msg = `Invalid type: "${typeof data}", number expected`
12
- throw new InvalidDecimalError(msg)
13
- }
14
-
15
- if(options.unsigned
16
- && data < 0)
17
- {
18
- const msg = `Expected an unsigned decimal`
19
- throw new InvalidDecimalError(msg)
20
- }
21
-
22
- if('min' in options
23
- && data < options.min)
24
- {
25
- const msg = `Decimal must be minimum: "${options.min}"`
26
- throw new InvalidDecimalError(msg)
27
- }
28
-
29
- if('max' in options
30
- && data > options.max)
31
- {
32
- const msg = `Decimal can't be more then: "${options.max}"`
33
- throw new InvalidDecimalError(msg)
34
- }
35
-
36
- if('gt' in options
37
- && data > options.gt)
38
- {
39
- const msg = `Decimal must be more then: "${options.gt}"`
40
- throw new InvalidDecimalError(msg)
41
- }
42
-
43
- if('lt' in options
44
- && data < options.lt)
45
- {
46
- const msg = `Decimal must be less then: "${options.lt}"`
47
- throw new InvalidDecimalError(msg)
48
- }
49
-
50
- if(options.enum
51
- &&!options.enum.includes(data))
52
- {
53
- const msg = `Expected one of the enumeral values: "${options.enum}"`
54
- throw new InvalidDecimalError(msg)
55
- }
56
- }
57
- }
58
-
59
- module.exports = ComposerValidatorDecimal
@@ -1,11 +0,0 @@
1
- const ComposerValidatorDecimal = require('.')
2
-
3
- class ComposerValidatorDecimalLocator
4
- {
5
- locate()
6
- {
7
- return new ComposerValidatorDecimal
8
- }
9
- }
10
-
11
- module.exports = ComposerValidatorDecimalLocator
@@ -1,10 +0,0 @@
1
- /**
2
- * @interface ComposerValidator
3
- */
4
-
5
- /**
6
- * @function ComposerValidator#valid
7
- * @param {Object} options
8
- * @param {*} data
9
- * @returns {void}
10
- */
@@ -1,13 +0,0 @@
1
- /**
2
- * @extends {Error}
3
- */
4
- class InvalidIntegerError extends Error
5
- {
6
- constructor(...a)
7
- {
8
- super(...a)
9
- this.code = 'E_INVALID_INTEGER'
10
- }
11
- }
12
-
13
- module.exports = InvalidIntegerError