@toa.io/core 0.4.0-dev.1 → 0.4.0-dev.6

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/core",
3
- "version": "0.4.0-dev.1",
3
+ "version": "0.4.0-dev.6",
4
4
  "description": "Toa Core",
5
5
  "author": "temich <tema.gurtovoy@gmail.com>",
6
6
  "homepage": "https://github.com/toa-io/toa#readme",
@@ -20,9 +20,9 @@
20
20
  },
21
21
  "dependencies": {
22
22
  "@rsql/parser": "1.2.4",
23
- "@toa.io/console": "0.4.0-dev.0",
24
- "@toa.io/generic": "0.4.0-dev.0",
25
- "@toa.io/yaml": "0.4.0-dev.1",
23
+ "@toa.io/console": "0.4.0-dev.6",
24
+ "@toa.io/generic": "0.4.0-dev.6",
25
+ "@toa.io/yaml": "0.4.0-dev.6",
26
26
  "clone-deep": "4.0.1"
27
27
  },
28
28
  "gitHead": "2be07592325b2e4dc823e81d882a4e50bf50de24"
package/src/locator.js CHANGED
@@ -2,7 +2,6 @@
2
2
 
3
3
  const { concat } = require('@toa.io/generic')
4
4
 
5
- // noinspection JSClosureCompilerSyntax
6
5
  /**
7
6
  * @implements {toa.core.Locator}
8
7
  */
@@ -32,6 +31,19 @@ class Locator {
32
31
  hostname (prefix) {
33
32
  return concat(prefix?.toLowerCase(), '-') + this.label
34
33
  }
34
+
35
+ /**
36
+ * @param {string} string
37
+ * @returns {Locator}
38
+ */
39
+ static parse (string) {
40
+ const [namespace, name] = string.split(DOT)
41
+
42
+ if (name === undefined) return new Locator(namespace)
43
+ else return new Locator(name, namespace)
44
+ }
35
45
  }
36
46
 
47
+ const DOT = '.'
48
+
37
49
  exports.Locator = Locator
@@ -79,3 +79,35 @@ describe('global', () => {
79
79
  expect(locator.hostname()).toStrictEqual(name.toLowerCase())
80
80
  })
81
81
  })
82
+
83
+ describe('parse', () => {
84
+ it('should be', async () => {
85
+ expect(Locator.parse).toBeInstanceOf(Function)
86
+ })
87
+
88
+ const namespace = generate()
89
+ const name = generate()
90
+ const id = `${namespace}.${name}`
91
+
92
+ it('should parse id', async () => {
93
+ const locator = Locator.parse(id)
94
+
95
+ expect(locator.namespace).toStrictEqual(namespace)
96
+ expect(locator.name).toStrictEqual(name)
97
+ })
98
+
99
+ it('should parse endpoint', async () => {
100
+ const endpoint = `${id}.${generate()}`
101
+ const locator = Locator.parse(endpoint)
102
+
103
+ expect(locator.namespace).toStrictEqual(namespace)
104
+ expect(locator.name).toStrictEqual(name)
105
+ })
106
+
107
+ it('should parse token as global', async () => {
108
+ const locator = Locator.parse(name)
109
+
110
+ expect(locator.namespace).toBeUndefined()
111
+ expect(locator.name).toStrictEqual(name)
112
+ })
113
+ })
@@ -42,9 +42,9 @@ declare namespace toa.core {
42
42
  }
43
43
 
44
44
  interface Factory {
45
- storage(locator: Locator): Storage
45
+ storage(locator: Locator, properties?: object): Storage
46
46
 
47
- migration(driver?: string): Migration
47
+ migration?(driver?: string): Migration
48
48
  }
49
49
  }
50
50