@toa.io/boot 0.7.0-dev.2 → 0.7.1-dev.0

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@toa.io/boot",
3
- "version": "0.7.0-dev.2",
3
+ "version": "0.7.1-dev.0",
4
4
  "description": "Toa Boot",
5
5
  "author": "temich <tema.gurtovoy@gmail.com>",
6
6
  "homepage": "https://github.com/toa-io/toa#readme",
@@ -19,12 +19,12 @@
19
19
  "test": "echo \"Error: run tests from root\" && exit 1"
20
20
  },
21
21
  "dependencies": {
22
- "@toa.io/core": "0.7.0-dev.2",
23
- "@toa.io/filesystem": "0.7.0-dev.2",
24
- "@toa.io/generic": "0.7.0-dev.2",
25
- "@toa.io/norm": "0.7.0-dev.2",
26
- "@toa.io/schema": "0.7.0-dev.2",
22
+ "@toa.io/core": "0.7.0",
23
+ "@toa.io/filesystem": "0.7.0",
24
+ "@toa.io/generic": "0.7.0",
25
+ "@toa.io/norm": "0.7.1-dev.0",
26
+ "@toa.io/schema": "0.7.0",
27
27
  "clone-deep": "4.0.1"
28
28
  },
29
- "gitHead": "f6267f46f0de28c834b2b7290338c32e6bc56e4d"
29
+ "gitHead": "7c52ddaad46512d8a8d913982d7330f83adcc98b"
30
30
  }
package/src/component.js CHANGED
@@ -11,9 +11,8 @@ const boot = require('./index')
11
11
  * @returns {Promise<toa.core.Component>}
12
12
  */
13
13
  const component = async (manifest) => {
14
- const name = manifest.entity.storage
15
14
  const locator = new Locator(manifest.name, manifest.namespace)
16
- const storage = boot.storage(locator, name, manifest.properties?.[name])
15
+ const storage = boot.storage(manifest)
17
16
  const context = await boot.context(manifest)
18
17
  const emission = boot.emission(manifest.events, locator)
19
18
  const schema = new Schema(manifest.entity.schema)
package/src/storage.js CHANGED
@@ -1,21 +1,43 @@
1
1
  'use strict'
2
2
 
3
+ const { join } = require('node:path')
3
4
  const extensions = require('./extensions')
4
5
 
5
6
  /**
6
- * @param {toa.core.Locator} locator
7
- * @param {string} provider
8
- * @param {any} properties
7
+ * @param {toa.norm.Component} component
9
8
  * @returns {toa.core.Storage}
10
9
  */
11
- const storage = (locator, provider, properties) => {
12
- const { Factory } = require(provider)
10
+ const storage = (component) => {
11
+ const [Factory, properties] = load(component)
13
12
 
14
13
  /** @type {toa.core.storages.Factory} */
15
14
  const factory = new Factory()
16
- const storage = factory.storage(locator, properties)
15
+ const storage = factory.storage(component.locator, properties)
17
16
 
18
17
  return extensions.storage(storage)
19
18
  }
20
19
 
20
+ function load (component) {
21
+ const reference = component.entity.storage
22
+ const path = require.resolve(reference, { paths: [component.path, __dirname] })
23
+ const { Factory } = require(path)
24
+
25
+ const pkg = loadPackageJson(component.path, reference)
26
+ const properties = pkg === null ? null : component.properties?.[pkg.name]
27
+
28
+ return [Factory, properties]
29
+ }
30
+
31
+ function loadPackageJson (root, reference) {
32
+ const packageJson = join(reference, 'package.json')
33
+
34
+ try {
35
+ const path = require.resolve(packageJson, { paths: [root, __dirname] })
36
+
37
+ return require(path)
38
+ } catch (e) {
39
+ return null
40
+ }
41
+ }
42
+
21
43
  exports.storage = storage