@superhero/core 1.8.5 → 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 -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
package/index.test.js ADDED
@@ -0,0 +1,94 @@
1
+ import assert from 'node:assert'
2
+ import fs from 'node:fs/promises'
3
+ import Core from '@superhero/core'
4
+ import { before, after, suite, test } from 'node:test'
5
+
6
+ suite('@superhero/core', () =>
7
+ {
8
+ const
9
+ testDir = './test',
10
+ fooDir = `${testDir}/foo`,
11
+ fooService = `${fooDir}/service.js`,
12
+ fooConfig = `${fooDir}/config.json`,
13
+ fooConfigDev = `${fooDir}/config-dev.json`
14
+
15
+ before(async () =>
16
+ {
17
+ // Create test directories
18
+ await fs.mkdir(fooDir, { recursive: true })
19
+
20
+ // Create mock service files
21
+ await fs.writeFile(fooService, 'export default class Foo { static locate() { return new Foo() } bootstrap(config) { this.bar = config.bar } }')
22
+
23
+ // Create mock config files
24
+ await fs.writeFile(fooConfig, JSON.stringify({ foo: { bar: 'baz' }, bootstrap: { foo: true }, locator: { 'foo': fooService } }))
25
+ await fs.writeFile(fooConfigDev, JSON.stringify({ foo: { bar: 'qux' } }))
26
+
27
+ // Disable console output for the tests
28
+ // Object.defineProperties(console,
29
+ // {
30
+ // info: { value: () => null },
31
+ // warn: { value: () => null }
32
+ // })
33
+ })
34
+
35
+ after(async () =>
36
+ {
37
+ await fs.rm(testDir, { recursive: true, force: true })
38
+ })
39
+
40
+ let core
41
+
42
+ test('Plain core bootstrap', async () =>
43
+ {
44
+ core = new Core()
45
+
46
+ await assert.doesNotReject(
47
+ core.bootstrap(),
48
+ 'Should bootstrap without errors')
49
+ })
50
+
51
+ test('Bootstraps a service successfully', async () =>
52
+ {
53
+ core = new Core()
54
+ await core.add(fooConfig)
55
+
56
+ await assert.doesNotReject(
57
+ core.bootstrap(),
58
+ 'Should bootstrap without errors')
59
+
60
+ const foo = core.locate('foo')
61
+
62
+ assert.ok(foo, 'Should have located the foo service')
63
+ assert.strictEqual(foo.bar, 'baz', 'Should have passed the correct configuration to the service')
64
+ })
65
+
66
+ test('Bootstraps a service with a branch variable', async () =>
67
+ {
68
+ const branch = 'dev'
69
+ core = new Core(branch)
70
+ await core.add(fooConfig)
71
+
72
+ await assert.doesNotReject(
73
+ core.bootstrap(),
74
+ 'Should bootstrap without errors')
75
+
76
+ const foo = core.locate('foo')
77
+
78
+ assert.ok(foo, 'Should have located the foo service')
79
+ assert.strictEqual(foo.bar, 'qux', 'Should have passed the correct configuration to the service')
80
+ })
81
+
82
+ test('Can cluster the core and bootstrap a service', async () =>
83
+ {
84
+ core = new Core()
85
+ await core.cluster(4)
86
+ await core.add(fooConfig)
87
+
88
+ await assert.doesNotReject(
89
+ core.bootstrap(),
90
+ 'Should bootstrap without errors')
91
+
92
+ await core.destruct()
93
+ })
94
+ })
package/package.json CHANGED
@@ -1,41 +1,27 @@
1
1
  {
2
2
  "name": "@superhero/core",
3
- "version": "1.8.5",
4
- "description": "Framework built with the domain driven design pattern in mind",
5
- "repository": "git@github.com:superhero/js.core.git",
3
+ "version": "4.0.0-beta.1",
4
+ "description": "Core functionalities for the superhero framework.",
6
5
  "main": "index.js",
7
6
  "license": "MIT",
8
- "keywords": [
9
- "framework",
10
- "http",
11
- "server",
12
- "eventbus",
13
- "ddd"
14
- ],
15
- "author": {
16
- "name": "Erik Landvall",
17
- "email": "erik@landvall.se",
18
- "url": "http://erik.landvall.se"
19
- },
20
- "scripts": {
21
- "doc-coverage": "nyc mocha './test/test.*.js' && nyc report --reporter=html --report-dir=./docs/coverage",
22
- "doc-tests": "mocha './test/test.*.js' --reporter mochawesome --reporter-options reportDir=docs/tests,reportFilename=index,showHooks=always",
23
- "test-coverage": "syntax-check && nyc mocha './test/test.*.js'",
24
- "test": "mocha './test/test.*.js'"
7
+ "type": "module",
8
+ "exports": {
9
+ ".": "./index.js"
25
10
  },
26
11
  "dependencies": {
27
- "@superhero/request": "1.0.9",
28
- "@superhero/debug": "1.1.11",
29
- "cookies": "0.7.2"
12
+ "@superhero/bootstrap": "^4.0.0",
13
+ "@superhero/config": "^4.0.5",
14
+ "@superhero/locator": "^4.0.4"
30
15
  },
31
- "devDependencies": {
32
- "@superhero/syntax-check": "0.0.1",
33
- "mocha": "5.1.0",
34
- "mochawesome": "3.0.2",
35
- "chai": "4.1.2",
36
- "nyc": "11.7.1"
16
+ "scripts": {
17
+ "test": "node --trace-warnings --test --experimental-test-coverage"
18
+ },
19
+ "author": {
20
+ "name": "Erik Landvall",
21
+ "email": "erik@landvall.se"
37
22
  },
38
- "engines": {
39
- "node": ">=10.0.0"
23
+ "repository": {
24
+ "type": "git",
25
+ "url": "https://github.com/superhero/config"
40
26
  }
41
27
  }
package/worker.js ADDED
@@ -0,0 +1,12 @@
1
+ import cluster from 'node:cluster'
2
+ import Core from '@superhero/core'
3
+
4
+ // If the worker is a core cluster worker start the core and
5
+ // listen for control messages from the primary process.
6
+ if(cluster.isWorker
7
+ && process.env.CORE_CLUSTER_WORKER)
8
+ {
9
+ const core = new Core()
10
+ process.on('message', core.onEvent.bind(core))
11
+ process.send('ready')
12
+ }
package/LICENCE DELETED
@@ -1,20 +0,0 @@
1
- The MIT License (MIT)
2
- Copyright (c) 2018 Erik Landvall
3
-
4
- Permission is hereby granted, free of charge, to any person obtaining a copy of
5
- this software and associated documentation files (the "Software"), to deal in
6
- the Software without restriction, including without limitation the rights to
7
- use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
8
- of the Software, and to permit persons to whom the Software is furnished to do
9
- so, subject to the following conditions:
10
-
11
- The above copyright notice and this permission notice shall be included in all
12
- copies or substantial portions of the Software.
13
-
14
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
- SOFTWARE.
@@ -1,7 +0,0 @@
1
- module.exports =
2
- {
3
- locator:
4
- {
5
- 'bootstrap' : __dirname
6
- }
7
- }
@@ -1,19 +0,0 @@
1
- class Bootstrap
2
- {
3
- constructor(locator)
4
- {
5
- this.locator = locator
6
- }
7
-
8
- async bootstrap()
9
- {
10
- const configuration = this.locator.locate('configuration')
11
- for(const key in configuration.config.bootstrap)
12
- {
13
- const bootstrap = this.locator.locate(configuration.config.bootstrap[key])
14
- await bootstrap.bootstrap()
15
- }
16
- }
17
- }
18
-
19
- module.exports = Bootstrap
@@ -1,16 +0,0 @@
1
- const Bootstrap = require('.')
2
-
3
- class BootstrapLocator
4
- {
5
- constructor(locator)
6
- {
7
- this.locator = locator
8
- }
9
-
10
- locate()
11
- {
12
- return new Bootstrap(this.locator)
13
- }
14
- }
15
-
16
- module.exports = BootstrapLocator
package/cli/config.js DELETED
@@ -1,7 +0,0 @@
1
- module.exports =
2
- {
3
- locator:
4
- {
5
- 'cli' : __dirname
6
- }
7
- }
package/cli/index.js DELETED
@@ -1,49 +0,0 @@
1
- class Cli
2
- {
3
- /**
4
- * @param {readline} readline
5
- * @param {string} prompt
6
- */
7
- constructor(readline, prompt)
8
- {
9
- this.readline = readline
10
- this.prompt = prompt
11
- }
12
-
13
- /**
14
- * @param {string} question
15
- * @param {function} completer @see https://nodejs.org/api/readline.html#readline_use_of_the_completer_function
16
- */
17
- question(question, completer)
18
- {
19
- return new Promise((accept, reject) =>
20
- {
21
- const rl = this.readline.createInterface(
22
- {
23
- prompt : this.prompt,
24
- input : process.stdin,
25
- output : process.stdout,
26
- completer
27
- })
28
-
29
- rl.question(question, (input) =>
30
- {
31
- rl.close()
32
- accept(input)
33
- })
34
- })
35
- }
36
-
37
- /**
38
- * @param {string|Buffer|Uint8Array|any} chunk not null...
39
- * @param {string} encoding utf8
40
- */
41
- write(chunk, encoding = 'utf8')
42
- {
43
- return new Promise((accept) =>
44
- process.stdout.write(chunk, encoding, () => accept())
45
- || process.stdout.emit('drain'))
46
- }
47
- }
48
-
49
- module.exports = Cli
package/cli/locator.js DELETED
@@ -1,17 +0,0 @@
1
- const
2
- Cli = require('.'),
3
- readline = require('readline')
4
-
5
- class CliLocator
6
- {
7
- locate()
8
- {
9
- const
10
- configuration = this.locator.locate('configuration'),
11
- prompt = configuration.find('cli.prompt')
12
-
13
- return new Cli(readline, prompt)
14
- }
15
- }
16
-
17
- module.exports = CliLocator
@@ -1,10 +0,0 @@
1
- class SchemaNotResolvableError extends ReferenceError
2
- {
3
- constructor(...a)
4
- {
5
- super(...a)
6
- this.code = 'E_SCHEMA_NOT_RESOLVABLE'
7
- }
8
- }
9
-
10
- module.exports = SchemaNotResolvableError
@@ -1,62 +0,0 @@
1
- const SchemaNotResolvable = require('./error/schema-not-resolvable')
2
-
3
- class ComposerBootstrap
4
- {
5
- constructor(locator, configuration, path)
6
- {
7
- this.locator = locator
8
- this.configuration = configuration
9
- this.path = path
10
- }
11
-
12
- bootstrap()
13
- {
14
- const
15
- composer = this.locator.locate('composer'),
16
- schemas = this.configuration.find('composer.schema'),
17
- filters = this.configuration.find('composer.filter'),
18
- validators = this.configuration.find('composer.validator')
19
-
20
- this.addSchemasToComposer(composer, schemas)
21
- this.addFiltersToComposer(composer, filters)
22
- this.addValidatorsToComposer(composer, validators)
23
- }
24
-
25
- addSchemasToComposer(composer, schemas)
26
- {
27
- if(schemas)
28
- for(const schemaName in schemas)
29
- if(this.path.isResolvable(schemas[schemaName]))
30
- {
31
- const schema = require(schemas[schemaName])
32
- composer.addSchema(schemaName, schema)
33
- }
34
- else
35
- {
36
- const msg = `Could not resolve path for schema: "${schemaName}", path: "${schemas[schemaName]}"`
37
- throw new SchemaNotResolvable(msg)
38
- }
39
- }
40
-
41
- addFiltersToComposer(composer, filters)
42
- {
43
- if(filters)
44
- for(const filterName in filters)
45
- {
46
- const filter = this.locator.locate(filters[filterName])
47
- composer.addFilter(filterName, filter)
48
- }
49
- }
50
-
51
- addValidatorsToComposer(composer, validators)
52
- {
53
- if(validators)
54
- for(const validatorName in validators)
55
- {
56
- const validator = this.locator.locate(validators[validatorName])
57
- composer.addValidator(validatorName, validator)
58
- }
59
- }
60
- }
61
-
62
- module.exports = ComposerBootstrap
@@ -1,20 +0,0 @@
1
- const ComposerBootstrap = require('.')
2
-
3
- class ComposerBootstrapLocator
4
- {
5
- constructor(locator)
6
- {
7
- this.locator = locator
8
- }
9
-
10
- locate()
11
- {
12
- const
13
- configuration = this.locator.locate('configuration'),
14
- path = this.locator.locate('path')
15
-
16
- return new ComposerBootstrap(this.locator, configuration, path)
17
- }
18
- }
19
-
20
- module.exports = ComposerBootstrapLocator
@@ -1,49 +0,0 @@
1
- module.exports =
2
- {
3
- bootstrap:
4
- {
5
- 'composer' : 'composer/bootstrap'
6
- },
7
- composer:
8
- {
9
- filter:
10
- {
11
- 'boolean' : 'composer/filter/boolean',
12
- 'decimal' : 'composer/filter/decimal',
13
- 'integer' : 'composer/filter/integer',
14
- 'json' : 'composer/filter/json',
15
- 'schema' : 'composer/filter/schema',
16
- 'string' : 'composer/filter/string',
17
- 'timestamp' : 'composer/filter/timestamp'
18
- },
19
- validator:
20
- {
21
- 'boolean' : 'composer/validator/boolean',
22
- 'decimal' : 'composer/validator/decimal',
23
- 'integer' : 'composer/validator/integer',
24
- 'json' : 'composer/validator/json',
25
- 'schema' : 'composer/validator/schema',
26
- 'string' : 'composer/validator/string',
27
- 'timestamp' : 'composer/validator/timestamp'
28
- }
29
- },
30
- locator:
31
- {
32
- 'composer' : __dirname,
33
- 'composer/bootstrap' : __dirname + '/bootstrap',
34
- 'composer/filter/boolean' : __dirname + '/filter/boolean',
35
- 'composer/filter/decimal' : __dirname + '/filter/decimal',
36
- 'composer/filter/integer' : __dirname + '/filter/integer',
37
- 'composer/filter/json' : __dirname + '/filter/json',
38
- 'composer/filter/schema' : __dirname + '/filter/schema',
39
- 'composer/filter/string' : __dirname + '/filter/string',
40
- 'composer/filter/timestamp' : __dirname + '/filter/timestamp',
41
- 'composer/validator/boolean' : __dirname + '/validator/boolean',
42
- 'composer/validator/decimal' : __dirname + '/validator/decimal',
43
- 'composer/validator/integer' : __dirname + '/validator/integer',
44
- 'composer/validator/json' : __dirname + '/validator/json',
45
- 'composer/validator/schema' : __dirname + '/validator/schema',
46
- 'composer/validator/string' : __dirname + '/validator/string',
47
- 'composer/validator/timestamp' : __dirname + '/validator/timestamp'
48
- }
49
- }
@@ -1,13 +0,0 @@
1
- /**
2
- * @extends {Error}
3
- */
4
- class FilterIsNotHoneringContractError extends Error
5
- {
6
- constructor(...a)
7
- {
8
- super(...a)
9
- this.code = 'E_FILTER_IS_NOT_HONERING_CONTRACT'
10
- }
11
- }
12
-
13
- module.exports = FilterIsNotHoneringContractError
@@ -1,13 +0,0 @@
1
- /**
2
- * @extends {Error}
3
- */
4
- class InvalidAttributeError extends Error
5
- {
6
- constructor(...a)
7
- {
8
- super(...a)
9
- this.code = 'E_COMPOSER_INVALID_ATTRIBUTE'
10
- }
11
- }
12
-
13
- module.exports = InvalidAttributeError
@@ -1,13 +0,0 @@
1
- /**
2
- * @extends {Error}
3
- */
4
- class InvalidCollectionError extends Error
5
- {
6
- constructor(...a)
7
- {
8
- super(...a)
9
- this.code = 'E_INVALID_COLLECTION'
10
- }
11
- }
12
-
13
- module.exports = InvalidCollectionError
@@ -1,13 +0,0 @@
1
- /**
2
- * @extends {Error}
3
- */
4
- class InvalidSchemaError extends Error
5
- {
6
- constructor(...a)
7
- {
8
- super(...a)
9
- this.code = 'E_COMPOSER_INVALID_SCHEMA'
10
- }
11
- }
12
-
13
- module.exports = InvalidSchemaError
@@ -1,13 +0,0 @@
1
- /**
2
- * @extends {Error}
3
- */
4
- class SchemaNotFoundError extends Error
5
- {
6
- constructor(...a)
7
- {
8
- super(...a)
9
- this.code = 'E_SCHEMA_NOT_FOUND'
10
- }
11
- }
12
-
13
- module.exports = SchemaNotFoundError
@@ -1,13 +0,0 @@
1
- /**
2
- * @extends {Error}
3
- */
4
- class ValidatorIsNotHoneringContractError extends Error
5
- {
6
- constructor(...a)
7
- {
8
- super(...a)
9
- this.code = 'E_VALIDATOR_IS_NOT_HONERING_CONTRACT'
10
- }
11
- }
12
-
13
- module.exports = ValidatorIsNotHoneringContractError
@@ -1,13 +0,0 @@
1
- /**
2
- * @extends {Error}
3
- */
4
- class ValidatorNotFoundError extends Error
5
- {
6
- constructor(...a)
7
- {
8
- super(...a)
9
- this.code = 'E_VALIDATOR_NOT_FOUND'
10
- }
11
- }
12
-
13
- module.exports = ValidatorNotFoundError
@@ -1,44 +0,0 @@
1
- /**
2
- * @implements {ComposerFilter}
3
- */
4
- class ComposerFilterBoolean
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(typeof data === 'string')
32
- {
33
- if(data.toLowerCase() === 'true')
34
- return true
35
-
36
- if(data.toLowerCase() === 'false')
37
- return false
38
- }
39
-
40
- return data
41
- }
42
- }
43
-
44
- module.exports = ComposerFilterBoolean
@@ -1,11 +0,0 @@
1
- const ComposerFilterBoolean = require('.')
2
-
3
- class ComposerFilterBooleanLocator
4
- {
5
- locate()
6
- {
7
- return new ComposerFilterBoolean
8
- }
9
- }
10
-
11
- module.exports = ComposerFilterBooleanLocator
@@ -1,38 +0,0 @@
1
- /**
2
- * @implements {ComposerFilter}
3
- */
4
- class ComposerFilterDecimal
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 = ComposerFilterDecimal
@@ -1,11 +0,0 @@
1
- const ComposerFilterDecimal = require('.')
2
-
3
- class ComposerFilterDecimalLocator
4
- {
5
- locate()
6
- {
7
- return new ComposerFilterDecimal
8
- }
9
- }
10
-
11
- module.exports = ComposerFilterDecimalLocator
@@ -1,10 +0,0 @@
1
- /**
2
- * @interface ComposerValidator
3
- */
4
-
5
- /**
6
- * @function ComposerFilter#filter
7
- * @param {Object} options
8
- * @param {*} data
9
- * @returns {void}
10
- */