@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.
- package/README.md +108 -739
- package/index.js +654 -54
- package/index.test.js +94 -0
- package/package.json +17 -34
- package/worker.js +12 -0
- package/LICENCE +0 -20
- package/bootstrap/config.js +0 -7
- package/bootstrap/index.js +0 -19
- package/bootstrap/locator.js +0 -16
- package/cli/config.js +0 -7
- package/cli/index.js +0 -49
- package/cli/locator.js +0 -17
- package/composer/bootstrap/error/schema-not-resolvable.js +0 -10
- package/composer/bootstrap/index.js +0 -62
- package/composer/bootstrap/locator.js +0 -20
- package/composer/config.js +0 -49
- package/composer/error/filter-is-not-honering-contract.js +0 -13
- package/composer/error/invalid-attribute.js +0 -13
- package/composer/error/invalid-collection.js +0 -13
- package/composer/error/invalid-schema.js +0 -13
- package/composer/error/schema-not-found.js +0 -13
- package/composer/error/validator-is-not-honering-contract.js +0 -13
- package/composer/error/validator-not-found.js +0 -13
- package/composer/filter/boolean/index.js +0 -44
- package/composer/filter/boolean/locator.js +0 -11
- package/composer/filter/decimal/index.js +0 -38
- package/composer/filter/decimal/locator.js +0 -11
- package/composer/filter/index.js +0 -10
- package/composer/filter/integer/index.js +0 -38
- package/composer/filter/integer/locator.js +0 -11
- package/composer/filter/json/index.js +0 -23
- package/composer/filter/json/locator.js +0 -11
- package/composer/filter/schema/error/missing-schema-definition.js +0 -13
- package/composer/filter/schema/index.js +0 -49
- package/composer/filter/schema/locator.js +0 -17
- package/composer/filter/string/index.js +0 -50
- package/composer/filter/string/locator.js +0 -11
- package/composer/filter/timestamp/index.js +0 -45
- package/composer/filter/timestamp/locator.js +0 -11
- package/composer/index.js +0 -180
- package/composer/locator.js +0 -17
- package/composer/validator/boolean/error/invalid.js +0 -13
- package/composer/validator/boolean/index.js +0 -17
- package/composer/validator/boolean/locator.js +0 -11
- package/composer/validator/decimal/error/invalid.js +0 -13
- package/composer/validator/decimal/index.js +0 -59
- package/composer/validator/decimal/locator.js +0 -11
- package/composer/validator/index.js +0 -10
- package/composer/validator/integer/error/invalid.js +0 -13
- package/composer/validator/integer/index.js +0 -65
- package/composer/validator/integer/locator.js +0 -11
- package/composer/validator/json/error/invalid.js +0 -13
- package/composer/validator/json/index.js +0 -23
- package/composer/validator/json/locator.js +0 -11
- package/composer/validator/schema/error/invalid.js +0 -13
- package/composer/validator/schema/index.js +0 -13
- package/composer/validator/schema/locator.js +0 -11
- package/composer/validator/string/error/invalid.js +0 -13
- package/composer/validator/string/index.js +0 -59
- package/composer/validator/string/locator.js +0 -11
- package/composer/validator/timestamp/error/invalid.js +0 -13
- package/composer/validator/timestamp/index.js +0 -54
- package/composer/validator/timestamp/locator.js +0 -11
- package/configuration/config.js +0 -7
- package/configuration/index.js +0 -23
- package/configuration/locator.js +0 -22
- package/console/config.js +0 -15
- package/console/index.js +0 -23
- package/console/locator.js +0 -21
- package/console/observer/error/config.js +0 -7
- package/console/observer/error/index.js +0 -14
- package/console/observer/error/locator.js +0 -17
- package/console/observer/info/config.js +0 -7
- package/console/observer/info/index.js +0 -14
- package/console/observer/info/locator.js +0 -17
- package/console/observer/warning/config.js +0 -7
- package/console/observer/warning/index.js +0 -14
- package/console/observer/warning/locator.js +0 -17
- package/core/config.js +0 -21
- package/core/error.js +0 -10
- package/deepcopy/config.js +0 -7
- package/deepcopy/error/failed-to-fast-copy.js +0 -10
- package/deepcopy/index.js +0 -18
- package/deepcopy/locator.js +0 -11
- package/deepfind/config.js +0 -7
- package/deepfind/index.js +0 -11
- package/deepfind/locator.js +0 -11
- package/deepfreeze/config.js +0 -7
- package/deepfreeze/index.js +0 -20
- package/deepfreeze/locator.js +0 -11
- package/deepmerge/config.js +0 -7
- package/deepmerge/index.js +0 -42
- package/deepmerge/locator.js +0 -11
- package/eventbus/bootstrap/error/observer-contract-not-honered.js +0 -10
- package/eventbus/bootstrap/index.js +0 -33
- package/eventbus/bootstrap/locator.js +0 -20
- package/eventbus/config.js +0 -17
- package/eventbus/index.js +0 -21
- package/eventbus/locator.js +0 -25
- package/eventbus/observer.js +0 -9
- package/factory.js +0 -55
- package/http/request/config.js +0 -7
- package/http/request/locator.js +0 -21
- package/http/server/config.js +0 -23
- package/http/server/dispatcher/chain/error/dispatcher-chain-ended.js +0 -10
- package/http/server/dispatcher/chain/index.js +0 -41
- package/http/server/dispatcher/chain/locator.js +0 -20
- package/http/server/dispatcher/collection/builder/error/dispatcher-can-not-be-resolved.js +0 -10
- package/http/server/dispatcher/collection/builder/error/not-honering-dispatcher-contract.js +0 -10
- package/http/server/dispatcher/collection/builder/index.js +0 -56
- package/http/server/dispatcher/collection/builder/locator.js +0 -20
- package/http/server/dispatcher/error/bad-gateway.js +0 -12
- package/http/server/dispatcher/error/bad-request.js +0 -12
- package/http/server/dispatcher/error/conflict.js +0 -12
- package/http/server/dispatcher/error/forbidden.js +0 -12
- package/http/server/dispatcher/error/gateway-timeout.js +0 -12
- package/http/server/dispatcher/error/index.js +0 -10
- package/http/server/dispatcher/error/method-not-allowed.js +0 -12
- package/http/server/dispatcher/error/not-implemented.js +0 -12
- package/http/server/dispatcher/error/page-not-found.js +0 -12
- package/http/server/dispatcher/error/request-timeout.js +0 -12
- package/http/server/dispatcher/error/server-error.js +0 -12
- package/http/server/dispatcher/error/service-unavailable.js +0 -12
- package/http/server/dispatcher/error/unauthorized.js +0 -12
- package/http/server/dispatcher/index.js +0 -26
- package/http/server/dispatcher/rest.js +0 -75
- package/http/server/error/no-endpoint-defined-in-route.js +0 -10
- package/http/server/error/view-contract-not-honered.js +0 -10
- package/http/server/index.js +0 -195
- package/http/server/locator.js +0 -34
- package/http/server/request/builder/index.js +0 -53
- package/http/server/request/builder/locator.js +0 -20
- package/http/server/route/builder/error/dto-invalid-reference.js +0 -10
- package/http/server/route/builder/error/routes-invalid-type.js +0 -10
- package/http/server/route/builder/index.js +0 -88
- package/http/server/route/builder/locator.js +0 -20
- package/http/server/session/builder/index.js +0 -34
- package/http/server/session/builder/locator.js +0 -11
- package/http/server/view/index.js +0 -12
- package/http/server/view/json/index.js +0 -17
- package/http/server/view/json/locator.js +0 -11
- package/http/server/view/locator.js +0 -11
- package/http/server/view/stream/index.js +0 -10
- package/http/server/view/stream/locator.js +0 -11
- package/http/server/view/text/index.js +0 -15
- package/http/server/view/text/locator.js +0 -11
- package/locator/constituent.js +0 -26
- package/locator/error/locator-not-implemented.js +0 -10
- package/locator/error/service-undefined.js +0 -10
- package/locator/index.js +0 -29
- package/path/config.js +0 -7
- package/path/index.js +0 -63
- package/path/locator.js +0 -11
- package/process/bootstrap/index.js +0 -31
- package/process/bootstrap/locator.js +0 -17
- package/process/config.js +0 -12
- package/process/index.js +0 -9
- package/process/locator.js +0 -11
- package/test/api/config.js +0 -43
- package/test/api/endpoint/append-calculation.js +0 -41
- package/test/api/endpoint/create-calculation.js +0 -18
- package/test/api/middleware/authentication.js +0 -27
- package/test/calculator/calculation.js +0 -29
- package/test/calculator/config.js +0 -14
- package/test/calculator/error/calculation-could-not-be-found.js +0 -13
- package/test/calculator/error/invalid-calculation-type.js +0 -13
- package/test/calculator/index.js +0 -67
- package/test/calculator/locator.js +0 -20
- package/test/init.js +0 -2
- package/test/logger/config.js +0 -15
- package/test/logger/index.js +0 -17
- package/test/logger/locator.js +0 -20
- package/test/mocha.opts +0 -4
- package/test/test.calculation.js +0 -58
- 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,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,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,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
|
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
|
package/composer/locator.js
DELETED
|
@@ -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,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,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
|