@toa.io/pointer 0.9.0-canary.2 → 0.20.0-alpha.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 (60) hide show
  1. package/package.json +14 -7
  2. package/readme.md +113 -78
  3. package/schemas/urimap.cos.yaml +2 -0
  4. package/source/Deployment.ts +90 -0
  5. package/source/annotation.test.ts +66 -0
  6. package/source/annotation.ts +46 -0
  7. package/source/createVariables.test.ts +186 -0
  8. package/source/createVariables.ts +12 -0
  9. package/source/index.ts +7 -0
  10. package/source/naming.ts +11 -0
  11. package/source/resolve.ts +63 -0
  12. package/transpiled/Deployment.d.ts +21 -0
  13. package/transpiled/Deployment.js +63 -0
  14. package/transpiled/Deployment.js.map +1 -0
  15. package/transpiled/annotation.d.ts +3 -0
  16. package/transpiled/annotation.js +62 -0
  17. package/transpiled/annotation.js.map +1 -0
  18. package/transpiled/createVariables.d.ts +4 -0
  19. package/transpiled/createVariables.js +12 -0
  20. package/transpiled/createVariables.js.map +1 -0
  21. package/transpiled/index.d.ts +6 -0
  22. package/transpiled/index.js +35 -0
  23. package/transpiled/index.js.map +1 -0
  24. package/transpiled/naming.d.ts +2 -0
  25. package/transpiled/naming.js +16 -0
  26. package/transpiled/naming.js.map +1 -0
  27. package/transpiled/resolve.d.ts +3 -0
  28. package/transpiled/resolve.js +54 -0
  29. package/transpiled/resolve.js.map +1 -0
  30. package/transpiled/tsconfig.tsbuildinfo +1 -0
  31. package/tsconfig.json +12 -0
  32. package/source/.deployment/.variables/credentials.js +0 -35
  33. package/source/.deployment/.variables/index.js +0 -7
  34. package/source/.deployment/.variables/pointer.js +0 -18
  35. package/source/.deployment/index.js +0 -8
  36. package/source/.deployment/validate.js +0 -19
  37. package/source/.deployment/variables.js +0 -22
  38. package/source/.pointer/env.js +0 -44
  39. package/source/.pointer/index.js +0 -9
  40. package/source/.pointer/label.js +0 -15
  41. package/source/.pointer/local.js +0 -17
  42. package/source/deployment.js +0 -17
  43. package/source/index.js +0 -11
  44. package/source/pointer.js +0 -34
  45. package/source/uris/construct.js +0 -18
  46. package/source/uris/index.js +0 -9
  47. package/source/uris/normalize.js +0 -12
  48. package/source/uris/resolve.js +0 -18
  49. package/source/uris/schema.yaml +0 -18
  50. package/source/uris/validate.js +0 -17
  51. package/source/variable.js +0 -12
  52. package/test/deployment.test.js +0 -92
  53. package/test/pointer.test.js +0 -213
  54. package/test/uris.fixtures.js +0 -10
  55. package/test/uris.test.js +0 -144
  56. package/test/variable.test.js +0 -37
  57. package/types/deployment.d.ts +0 -21
  58. package/types/pointer.d.ts +0 -19
  59. package/types/uris.d.ts +0 -27
  60. package/types/variable.d.ts +0 -8
package/test/uris.test.js DELETED
@@ -1,144 +0,0 @@
1
- 'use strict'
2
-
3
- const clone = require('clone-deep')
4
- const { generate } = require('randomstring')
5
- const { random } = require('@toa.io/generic')
6
- const { Locator } = require('@toa.io/core')
7
-
8
- const fixtures = require('./uris.fixtures')
9
- const { uris } = require('../')
10
-
11
- const gen = () => 'schema://host-' + generate().toLowerCase() + ':' + (random(1000) + 1000)
12
-
13
- describe('construct', () => {
14
- const construct = uris.construct
15
-
16
- let annotations
17
-
18
- beforeEach(() => {
19
- annotations = clone(fixtures.annotations)
20
- })
21
-
22
- it('should be', () => {
23
- expect(construct).toBeDefined()
24
- expect(construct).toBeInstanceOf(Function)
25
- })
26
-
27
- describe('normalize', () => {
28
- it('should treat string value as default', () => {
29
- const declaration = gen()
30
- const result = construct(declaration)
31
-
32
- expect(result).toStrictEqual({ default: declaration })
33
- })
34
-
35
- it('should allow dot notation', () => {
36
- const url = gen()
37
-
38
- annotations['foo.bar'] = url
39
-
40
- construct(annotations)
41
-
42
- expect(annotations['foo.bar']).toStrictEqual(url)
43
- })
44
-
45
- it('should allow dot notation with namespace value', () => {
46
- annotations.foo = gen()
47
- annotations['foo.bar'] = gen()
48
-
49
- expect(() => construct(annotations)).not.toThrow()
50
- })
51
- })
52
-
53
- describe('validate', () => {
54
- it('should throw if declaration is not a string or an object', () => {
55
- // noinspection JSCheckFunctionSignatures
56
- expect(() => construct(1)).toThrow(TypeError)
57
- expect(() => construct(null)).toThrow(TypeError)
58
- })
59
-
60
- it('should throw if property is not url', () => {
61
- annotations.foo = 'not url'
62
-
63
- expect(() => construct(annotations)).toThrow(TypeError)
64
- })
65
- })
66
- })
67
-
68
- describe('resolve', () => {
69
- const resolve = uris.resolve
70
-
71
- let name
72
- let namespace
73
- let uri
74
-
75
- /** @type {toa.pointer.URIs} */
76
- let annotation
77
-
78
- /** @type {toa.core.Locator} */
79
- let locator
80
-
81
- beforeEach(() => {
82
- name = generate()
83
- namespace = generate()
84
- uri = gen()
85
-
86
- annotation = {
87
- [namespace + '.' + name]: uri
88
- }
89
-
90
- locator = new Locator(name, namespace)
91
- })
92
-
93
- it('should be', () => {
94
- expect(uris.resolve).toBeDefined()
95
- expect(uris.resolve).toBeInstanceOf(Function)
96
- })
97
-
98
- it('should resolve by id', () => {
99
- const { url } = resolve(locator, annotation)
100
-
101
- expect(url).toBeInstanceOf(URL)
102
- expect(url.href).toStrictEqual(uri)
103
- })
104
-
105
- it('should throw if not found', () => {
106
- const name = generate()
107
- const namespace = generate()
108
- const locator = new Locator(name, namespace)
109
-
110
- expect(() => resolve(locator, annotation)).toThrow(`URI annotation for '${locator.id}' is not found`)
111
- })
112
-
113
- it('should resolve by namespace', () => {
114
- annotation[namespace] = uri
115
-
116
- const { url } = resolve(locator, annotation)
117
-
118
- expect(url.href).toStrictEqual(uri)
119
- })
120
-
121
- it('should resolve default', () => {
122
- annotation = { default: gen() }
123
-
124
- const { url } = resolve(locator, annotation)
125
-
126
- expect(url.href).toStrictEqual(annotation.default)
127
- })
128
-
129
- it('should resolve global locators', () => {
130
- const name = generate()
131
- const locator = new Locator(name)
132
- const uri = gen()
133
-
134
- annotation = { [name]: uri }
135
-
136
- const { url } = resolve(locator, annotation)
137
-
138
- expect(url.href).toStrictEqual(uri)
139
- })
140
- })
141
-
142
- it('should expose validate function', async () => {
143
- expect(uris.validate).toBeInstanceOf(Function)
144
- })
@@ -1,37 +0,0 @@
1
- 'use strict'
2
-
3
- const { generate } = require('randomstring')
4
- const { Locator } = require('@toa.io/core')
5
- const { random, letters: { up } } = require('@toa.io/generic')
6
-
7
- const { variable } = require('../')
8
-
9
- it('should be', () => {
10
- expect(variable).toBeInstanceOf(Function)
11
- })
12
-
13
- it('should create variable', () => {
14
- const prefix = 'foo-bar'
15
- const namespace = generate()
16
- const component = generate()
17
- const locator = new Locator(component, namespace)
18
- const name = generate()
19
-
20
- let value = generate()
21
-
22
- const string = variable(prefix, locator, name, value)
23
-
24
- const expected = {
25
- name: `TOA_${up(prefix)}_${locator.uppercase}_${up(name)}`,
26
- value
27
- }
28
-
29
- expect(string).toStrictEqual(expected)
30
-
31
- value = random()
32
- expected.value = value
33
-
34
- const number = variable(prefix, locator, name, value)
35
-
36
- expect(number).toStrictEqual(expected)
37
- })
@@ -1,21 +0,0 @@
1
- import { dependency } from '@toa.io/operations/types/deployment'
2
- import { dependencies } from '@toa.io/norm/types'
3
- import * as _uris from './uris'
4
-
5
- declare namespace toa.pointer {
6
-
7
- namespace deployment {
8
-
9
- type Options = {
10
- prefix: string
11
- }
12
-
13
- }
14
-
15
- type Deployment = (
16
- instances: dependencies.Instance[],
17
- uris: _uris.URIs,
18
- options: deployment.Options
19
- ) => dependency.Declaration
20
-
21
- }
@@ -1,19 +0,0 @@
1
- declare namespace toa.pointer {
2
-
3
- type Options = {
4
- protocol: string // for local environment
5
- }
6
-
7
- interface Pointer {
8
- protocol: string
9
- host: string
10
- port: number
11
- hostname: string
12
- path: string
13
- username: string
14
- password: string
15
- reference: string
16
- label: string // safe for logging
17
- }
18
-
19
- }
package/types/uris.d.ts DELETED
@@ -1,27 +0,0 @@
1
- import { Locator } from '@toa.io/core/types'
2
-
3
- declare namespace toa.pointer {
4
-
5
- namespace uris {
6
-
7
- type Node = string | {
8
- [key: string]: Node
9
- }
10
-
11
- type Resolution = {
12
- url: URL
13
- entry: string
14
- }
15
-
16
- type Resolver = (locator: Locator, uris: URIs) => Resolution
17
-
18
- }
19
-
20
- type URIs = string | {
21
- default?: string
22
- [key: string]: uris.Node
23
- }
24
-
25
- }
26
-
27
- export type URIs = toa.pointer.URIs
@@ -1,8 +0,0 @@
1
- import { Locator } from '@toa.io/core/types'
2
- import { dependency } from '@toa.io/operations/types/deployment'
3
-
4
- declare namespace toa.pointer {
5
- type Variable = (scope: string, locator: Locator, label: string, value: string | number) => dependency.Variable
6
- }
7
-
8
- export const variable: toa.pointer.Variable