@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.
- package/README.md +108 -739
- package/index.js +654 -54
- package/index.test.js +94 -0
- package/package.json +17 -31
- 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
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": "
|
|
4
|
-
"description": "
|
|
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
|
-
"
|
|
9
|
-
|
|
10
|
-
"
|
|
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/
|
|
28
|
-
"@superhero/
|
|
29
|
-
"
|
|
12
|
+
"@superhero/bootstrap": "^4.0.0",
|
|
13
|
+
"@superhero/config": "^4.0.5",
|
|
14
|
+
"@superhero/locator": "^4.0.4"
|
|
30
15
|
},
|
|
31
|
-
"
|
|
32
|
-
"
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
"
|
|
36
|
-
"
|
|
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
|
-
"
|
|
39
|
-
"
|
|
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.
|
package/bootstrap/config.js
DELETED
package/bootstrap/index.js
DELETED
|
@@ -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
|
package/bootstrap/locator.js
DELETED
package/cli/config.js
DELETED
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,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
|
package/composer/config.js
DELETED
|
@@ -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,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,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
|