@toa.io/pointer 0.4.0-dev.0 → 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/pointer",
3
- "version": "0.4.0-dev.0",
3
+ "version": "0.4.0-dev.6",
4
4
  "description": "Toa Pointer",
5
5
  "homepage": "https://toa.io",
6
6
  "author": {
@@ -23,9 +23,9 @@
23
23
  },
24
24
  "main": "source/index.js",
25
25
  "dependencies": {
26
- "@toa.io/console": "0.4.0-dev.0",
27
- "@toa.io/generic": "0.4.0-dev.0",
28
- "@toa.io/schema": "0.4.0-dev.0",
29
- "@toa.io/yaml": "0.4.0-dev.0"
26
+ "@toa.io/console": "0.4.0-dev.6",
27
+ "@toa.io/generic": "0.4.0-dev.6",
28
+ "@toa.io/schema": "0.4.0-dev.6",
29
+ "@toa.io/yaml": "0.4.0-dev.6"
30
30
  }
31
31
  }
@@ -2,6 +2,8 @@
2
2
 
3
3
  const { env } = require('./env')
4
4
  const { local } = require('./local')
5
+ const { label } = require('./label')
5
6
 
6
7
  exports.env = env
7
8
  exports.local = local
9
+ exports.label = label
@@ -0,0 +1,15 @@
1
+ 'use strict'
2
+
3
+ /**
4
+ * @param {URL} url
5
+ * @returns {string}
6
+ */
7
+ const label = (url) => {
8
+ const safe = new URL(url.href)
9
+
10
+ safe.password = ''
11
+
12
+ return safe.href
13
+ }
14
+
15
+ exports.label = label
package/source/pointer.js CHANGED
@@ -27,20 +27,8 @@ class Pointer {
27
27
  this.username = url.username
28
28
  this.password = url.password
29
29
  this.reference = url.href
30
- this.label = label(url)
30
+ this.label = get.label(url)
31
31
  }
32
32
  }
33
33
 
34
- /**
35
- * @param {URL} url
36
- * @returns {string}
37
- */
38
- const label = (url) => {
39
- const safe = new URL(url.href)
40
-
41
- safe.password = ''
42
-
43
- return safe.href
44
- }
45
-
46
34
  exports.Pointer = Pointer
@@ -2,27 +2,15 @@
2
2
 
3
3
  /** @type {toa.pointer.uris.Resolver} */
4
4
  const resolve = (locator, uris) => {
5
- let entry
5
+ const keys = [locator.id, locator.namespace, 'default']
6
+ const entry = keys.find((key) => key in uris)
7
+ const uri = uris[entry]
6
8
 
7
- /** @type {string} */
8
- let uri
9
-
10
- const entries = [locator.id, locator.namespace, 'default']
11
-
12
- for (const key of entries) {
13
- if (typeof uris[key] === 'string') {
14
- uri = uris[key]
15
- entry = key
16
-
17
- break
18
- }
19
- }
20
-
21
- if (uri === undefined) throw new Error(`URI annotation for '${locator.id}' is not found`)
9
+ if (entry === undefined) throw new Error(`URI annotation for '${locator.id}' is not found`)
22
10
 
23
11
  const url = new URL(uri)
24
12
 
25
- if (url.hostname === '') throw new Error(`URI annotation for '${locator.id}' must contain hostname`)
13
+ if (url.hostname === '') throw new Error(`URI annotation for '${locator.id}' must contain a hostname`)
26
14
 
27
15
  return { url, entry }
28
16
  }
@@ -1,13 +1,13 @@
1
1
  'use strict'
2
2
 
3
+ const { generate } = require('randomstring')
4
+ const { encode, letters: { up } } = require('@toa.io/generic')
5
+
3
6
  const mock = { console: { info: jest.fn(), warn: jest.fn() } }
4
7
 
5
8
  jest.mock('@toa.io/console', () => mock)
6
9
 
7
- const { generate } = require('randomstring')
8
10
  const { Locator } = require('@toa.io/core')
9
- const { encode, letters: { up } } = require('@toa.io/generic')
10
-
11
11
  const { Pointer } = require('../')
12
12
 
13
13
  it('should be', () => {